I've been stuck on this for a while now, trying to make this work in the UCI. I'm trying to update the "To" value on a Portal Comment form based on changes to another value. When the variable value is changed to one type of value I'm able to set the "To" field's Entity Type to system user, and the default view to a specific set users. When the variable is set to the other type of I want to get the Contact from the related Case form - this is where I'm running into issues. Every time I update the variable value I get a "Cannot read property 'partytype' of null" error. I've been over it easily 100 times trying different things without much luck. I think formContext.data.attributes would do the trick, but I haven't been able to get it to work, and I haven't found any decent documentation on it. Has anybody else run into a similar problem? Here is the current script I'm working with:
function To(executionContext)
{
var formContext = executionContext.getFormContext();
var parameters = formContext.data.attributes.get("Parameters")
var globalContext = Xrm.Utility.getGlobalContext();
if ( formContext.getAttribute( "x_commentreason" ).getValue() == 946830000 || formContext.getAttribute( "x_commentreason" ).getValue() == 946830001 || formContext.getAttribute( "x_commentreason" ).getValue() == 946830002 || formContext.getAttribute( "x_commentreason" ).getValue() == 946830003 || formContext.getAttribute( "x_commentreason" ).getValue() == 946830006)
{formContext.getAttribute("to").setValue(null);
formContext.getControl("to").setEntityTypes(["contact"]);
formContext.getAttribute("x_assignto").setValue(null);
var entityTypeName = null;
if ( globalContext.client.getClient() === "Web" ) {
var entityTypeCode = parseInt( parameters["partytype"], 10 );
entityTypeName = Xrm.Internal.getEntityName( entityTypeCode );
}
else
{
entityTypeName = parameters["partytype"];
}
formContext.getAttribute( "to" ).setValue( [{ id: parameters["partyid"], name: parameters["partyname"], entityType: entityTypeName}] );
}
else{ formContext.getAttribute("to").setValue(null);
formContext.getAttribute("x_assignto").setValue(null);
formContext.getControl("to").setEntityTypes(["systemuser"]);
formContext.getControl("to").setDefaultView( ABCDEFG-HIJK-LMNO-PQRS-TUVWXYZABCDE}");}
}