Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Portal Comment TypeError: Cannot read property 'web' of undefined

Posted on by Microsoft Employee

Hi,

Since we updated to Wave 2, I'm getting a script error when creating new Portal Comments in the Customer Service Hub.

The "Direction", "To" and "From" fields are no longer filled out automatically.The error "cannot read property 'web' of undefined'" regards the following script:

function initialize()
{
	if ( Xrm.Page.ui.getFormType() == 1 && ( Xrm.Page.context.client.getClient() === Xrm.ClientName.web || Xrm.Page.context.client.getClient() === Xrm.ClientName.mobile ) ) {

		//Set the default value for direction code as Outgoing for Web Client.
		if ( Xrm.Page.getAttribute( "adx_portalcommentdirectioncode" ).getValue() != null ) {
			Xrm.Page.getAttribute( "adx_portalcommentdirectioncode" ).setValue( 2 );
		}

		//Set From lookup field with the value based on current user.
		Xrm.Page.getAttribute( "from" ).setValue( [{ id: Xrm.Page.context.getUserId(), name: Xrm.Page.context.getUserName(), entityType: "systemuser" }] );

		//Set To Lookup field value based on the Query String parameters passed from Case form.
		var parameters = Xrm.Page.context.getQueryStringParameters();

		if ( parameters["partyid"] != null && parameters["partyname"] != null && parameters["partytype"] != null ) {
			var entityTypeName = null;
			if ( Xrm.Page.context.client.getClient() === Xrm.ClientName.web ) {
				var entityTypeCode = parseInt( parameters["partytype"], 10 );
				entityTypeName = Xrm.Internal.getEntityName( entityTypeCode )
			}
			else
			{
				entityTypeName = parameters["partytype"];
			}
			Xrm.Page.getAttribute( "to" ).setValue( [{ id: parameters["partyid"], name: parameters["partyname"], entityType: entityTypeName }] );
		}
	}
}

Has anyone else encountered this problem since the Wave 2 update?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Clofly,

    Finally fixed it! There were two issues. One was the condition in the if statement: the primary contactid value can't be both an empty string and a null value at the same value so with this logic the script never went to "else".

    Second there was a problem with the loop, it would overwrite correct data so I changed it to just use the first result:

    if (results.value.length > 0)

    Very grateful for all your help!

    Kind regards,

    Nina

  • RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Clofly,

    I understand, and that is what I'm trying to do but I can't get it to work.
    I've created a variable for the contact field, so I can see its value when running the code.
    The value is definitely null, but still the code jumps into line 72.

    pastedimage1571320528509v2.png

    pastedimage1571320423254v1.png

    Kind regards,

    Nina

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Nina,

    You should make the step jump into else snippet if there is no data in Contact field:

    if (results.value[i]["_primarycontactid_value"] != null || results.value[i]["_primarycontactid_value"] != "") {
    
      Xrm.Page.getAttribute("to").setValue([{
        id: results.value[i]["_primarycontactid_value"],
        name: results.value[i]["_primarycontactid_value@OData.Community.Display.V1.FormattedValue"],
        entityType: results.value[i]["_primarycontactid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]
      }]);
    
    } 
    // Jump to else if there is no contact data in Contact field
    else {
    
      Xrm.Page.getAttribute("to").setValue([{
        id: _customerid_value,
        name: _customerid_value_formatted,
        entityType: _customerid_value_lookuplogicalname
      }]);
    
    }

    Regards,

    Clofly

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Clofly,

    Yes, now the contact is filled out in the "To" field!

    However, when contact field is empty, the "To" field is left empty as well, even when we do have a value in the Customer field (so the account name) :(

    Again, this is only a problem in the hub environment.

    If there's a quick fix please tell me, but I can definitely live with this if you don't have the answer.

    Kind regards,

    Nina

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Nina,

    It seems that primarycontactid is also formatted as _primarycontactid_value,

    you could try replace with following attribute:

    results.value[i]["_primarycontactid_value"]

    results.value[i]["_primarycontactid_value@OData.Community.Display.V1.FormattedValue"] 

    results.value[i]["_primarycontactid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]

    Regards,

    Clofly

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Clofly,

    Honestly, I don't know why you're still sticking with me on this problem but I really really appreciate it!

    Unfortunately it's still not solved for the Customer Service Hub.
    The contact field logical name is primarycontactid. (I tried all lower cases and PrimaryContactId, as you will see in the image below).

    After line 70 the code steps into SkypeChannelClient.js.

    pastedimage1571228207253v2.png

    I understand if you want to give up, but if not, let me know if you need additional information.

    I tried to add the full code but I'm getting an "access denied" message when I do so...

    Kind regards,

    Nina

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Nina,

    I don't know what your Contact field logical name is, so I assume it's new_contact, so please replace it with your owns.

    make new snippet inside for loop in SetToField function.

            for (var i = 0; i < results.value.length; i  ) {
    
              var _customerid_value = results.value[i]["_customerid_value"];
    
              var _customerid_value_formatted = results.value[i]["_customerid_value@OData.Community.Display.V1.FormattedValue"];
    
              var _customerid_value_lookuplogicalname = results.value[i]["_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
    
              if (results.value[i]["new_contact"] != null || results.value[i]["new_contact"] != "") {
    
                Xrm.Page.getAttribute("to").setValue([{ 
                  id: results.value[i]["new_contact"], 
                  name: results.value[i]["new_contact@OData.Community.Display.V1.FormattedValue"], 
                  entityType: results.value[i]["new_contact@Microsoft.Dynamics.CRM.lookuplogicalname"] }]);
    
              } else {
                Xrm.Page.getAttribute("to").setValue([{ id: _customerid_value, name: _customerid_value_formatted, entityType: _customerid_value_lookuplogicalname }]);
              }
    
            }

    If Contact field of Case contains data, then prefill it with contact data instead of Customer data.

    Regards,

    Clofly

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Ah, I didn't even realize we must have some custom solution here.

    We use two fields: Customer and Contact.

    In the Customer field, we always fill out an Account name (I built a restriction for this on the case form)

    In the Contact field, we fill out the name of a Contact linked to that Account.

    If the Contact field is empty, the Portal Comment should be directed to the Account.

    If there is a Contact, the Portal Comment should go to the Contact (and a workflow is activated so the contact gets an email notification of the new Portal Comment).

    pastedimage1571130534662v1.png

    Kind regards,

    Nina

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Portal Comment TypeError: Cannot read property 'web' of undefined

    Hi Nina,

    Could you describe more details of issue "in the customer service hub it always fills out the account name, even when a contact name is known" ?

    The To field will be filled with Customer field data,

    if it's a contact, then To field will be filled with Contact.

    if it's an account, then To field will be filled with Account.

    pastedimage1571124466724v1.png

    pastedimage1571124680313v1.png

    Please let me know if you still have any doubt :) 

    Regards,

    Clofly

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