web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

JScript error - Help needed

(0) ShareShare
ReportReport
Posted on by 175

Hi, users are getting an error when creating a new 'Portal Comment' (ADX entity) in D365.  I need help troubleshooting/resolving this.  ANy feedback is welcome and appreciated - thanks!  

The error is a script error OnLoad:

pastedimage1587406582635v2.png

Here is Error Log:
TypeError: Cannot read property 'web' of undefined
at initialize (soprissystems.crm.dynamics.com/.../adx_portalcomment_form.js:3:98)
at mp.executeFunction (soprissystems.crm.dynamics.com/.../app.js
at mp.execute (soprissystems.crm.dynamics.com/.../app.js
at up._executeIndividualEvent (soprissystems.crm.dynamics.com/.../app.js
at up._executeEventHandler (soprissystems.crm.dynamics.com/.../app.js
at Object.execute (soprissystems.crm.dynamics.com/.../app.js
at O._executeSyncAction (soprissystems.crm.dynamics.com/.../app.js
at O._executeSync (soprissystems.crm.dynamics.com/.../app.js
at O.executeAction (soprissystems.crm.dynamics.com/.../app.js
at t.dispatch (soprissystems.crm.dynamics.com/.../app.js

Here are Form Properties:
pastedimage1587406547434v1.png

Here is the web resource code it points to:

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

I have the same question (0)
  • Verified answer
    Marco.P Profile Picture
    2,405 on at

    Hi,

    take a look a this:

    community.dynamics.com/.../portal-comment-typeerror-cannot-read-property-web-of-undefined

     

    Try replace Xrm.ClientName.web

    with 

    Xrm.Page.context.client.getClient() === "Web"

    or better since Xrm.Page is deprecated

    Xrm.Utility.getGlobalContext().client.getClient()==="Web"

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/client

    Hope it helps,

    Marco

  • William Bradley Profile Picture
    175 on at

    Thanks. I used this code and it seemed to solve the Script error issue.

    function initialize()

    {

    if ( Xrm.Page.ui.getFormType() == 1 && ( Xrm.Page.context.client.getClient().toLowerCase() === "web" || Xrm.Page.context.client.getClient().toLowerCase() === "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().toLowerCase() === "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 }] );

    }

    }

    }

  • William Bradley Profile Picture
    175 on at

    I am now looking to set the value of the "To" field onLoad of Portal Comment, if the Regarding Case "Contact" lookup contains data.  Do you happen to have an example of a function I can use for this?  

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans