Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

"Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

Posted on by 15

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}");}
}

 

  • 5th4th Profile Picture
    5th4th 15 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    No, I haven't had any luck yet.

  • Divyamahajan Profile Picture
    Divyamahajan 5 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    Were you able to set To field in portal comment.

  • 5th4th Profile Picture
    5th4th 15 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    I have the javascript saved as a webresouce on a Portal Comment form. Our users are populating a custom field called "Comment Reason". Based on the comment reason they pick, the "To" field on the Portal Comment form will either be populated with the contact from the regarding Incident, or cleared so that the user can list a different user in the "To" field, the latter is working correctly.

    The field I'm trying to update with formContext.getAttribute( "to" ) is in the Portal Comment entity. What I'm struggling to do is populate that field with is the primarycontactid from the regarding incident.

  • rthompson Profile Picture
    rthompson 1,530 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    From what I am seeing you are trying to use standard javascript that you would use in a portal and trying to use that in UCI.

    What entity are you using.

    Parameters in UCI will just return a null.

    Where are you getting this field formContext.getAttribute( "to" ).

    It looks like you are trying to combine code.

  • 5th4th Profile Picture
    5th4th 15 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    Hi, yeah that was just typo I missed clearing out that ID to post it here, thanks for catching it though. This is only for a main form to tie in with some record assignment flows, the webform for the portal wont have any events at this point.

  • rthompson Profile Picture
    rthompson 1,530 on at
    RE: "Cannot read property 'partytype' of null" trying to set Portal Comment "To" to get regarding Case primarycontactid

    Hi,

    I have not spend much time reviewing your code.

    However I do see this error in your code.

    You are missing your "{

    formContext.getControl("to").setDefaultView ("{ ABCDEFG-HIJK-LMNO-PQRS-TUVWXYZABCDE}");}

    Also,  I am sure you are aware that this code does not work in a portal.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans