Skip to main content

Notifications

Announcements

No record found.

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

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript error - Help needed

    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?  

  • William Bradley Profile Picture
    William Bradley 175 on at
    RE: JScript error - Help needed

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

    }

    }

    }

  • Verified answer
    Marco.P Profile Picture
    Marco.P 2,405 on at
    RE: JScript error - Help needed

    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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans