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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

When i am trying to get the status of the record from lookup using the below script on form load i am facng an issue. Please help me what i can do to resolve the issue.

(0) ShareShare
ReportReport
Posted on by 20

function displaynotification(executionContext){
var formContext = executionContext.getFormContext();
debugger;
var conatt = formContext.getAttribute("ctp_ctpapplicantsappversion");
var conatt1 = formContext.getAttribute("ctp_ctpapplicantsappversion").getValue();
if( conatt && conatt1 != null){
var conID = conatt1[0].id;
var infoID = "info";
var warningid = "warning";
Xrm.WebApi.retrieveRecord("ctp_ctpapplicantsappversion", "cad0116f-ee80-ed11-81ad-000d3a565815", "?$select=statecode").then(
function success(result) {
var res = result.statecode().getValue();
if(res == "active" ){
formContext.ui.setFormNotification("Record ID of CTP Applicants APP is" + conID, "INFO", infoID);
}
}
);
}
}

What wrong in this code when i try to load this script on form onload i am getting below error

ReferenceError: Web resource method does not exist: displaynotification
at y._handleMethodNotExistError (ctp.crm.dynamics.com/.../app.js
at y.execute (ctp.crm.dynamics.com/.../app.js
at ctp.crm.dynamics.com/.../app.js
at i (ctp.crm.dynamics.com/.../app.js
at ee._executeIndividualEvent (ctp.crm.dynamics.com/.../app.js
at ee._executeEventHandler (ctp.crm.dynamics.com/.../app.js
at Object.execute (ctp.crm.dynamics.com/.../app.js
at N._executeSyncAction (ctp.crm.dynamics.com/.../app.js
at N._executeSync (ctp.crm.dynamics.com/.../app.js
at N.executeAction (ctp.crm.dynamics.com/.../app.js
at t.dispatch (ctp.crm.dynamics.com/.../app.js
at Object.dispatch (ctp.crm.dynamics.com/.../app.js
at Object.dispatch (ctp.crm.dynamics.com/.../app.js
at dispatch (ctp.crm.dynamics.com/.../app.js
at It (ctp.crm.dynamics.com/.../17.js
at ctp.crm.dynamics.com/.../24.js

Error Details:
Event Name: onload
Function Name: displaynotification
Web Resource Name: ctp_configstatus
Solution Name: Active
Publisher Name: DefaultPublisherorg524de1c3

Please help me resolve it

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: When i am trying to get the status of the record from lookup using the below script on form load i am facng an issue. Please help me what i can do to resolve the issue.

    Hello,

    Try to replace line

    var res = result.statecode().getValue();

    with line

    var res = result["statecode@OData.Community.Display.V1.FormattedValue"];

  • Suggested answer
    RodRodriguez Profile Picture
    on at
    RE: When i am trying to get the status of the record from lookup using the below script on form load i am facng an issue. Please help me what i can do to resolve the issue.

    There seems to be an issue with the function "displaynotification". The error message "ReferenceError: Web resource method does not exist: displaynotification" suggests that the function might not be defined or registered correctly as a web resource in Dynamics.

    To troubleshoot this issue, you can try the following:

    1. Make sure that the function "displaynotification" is defined in the web resource and that it is being called correctly.

    2. Check if the web resource is registered correctly in Dynamics. Make sure that the web resource is properly added to the form or the component where it is being used.

    3. If you are using the "Xrm.WebApi" object to make a web API request, make sure that you have the correct syntax and that the required parameters are being passed correctly.

    4. If the issue persists, you can try debugging the function by adding a "debugger;" statement at the beginning of the function and then use the browser's developer console to inspect the variables and see what might be causing the error.

  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    RE: When i am trying to get the status of the record from lookup using the below script on form load i am facng an issue. Please help me what i can do to resolve the issue.

    Hi,

    1. Please all closing braces properly.

    2. you need make changes in success call back to use formatted values as result['statecode@OData.Community.Display.V1.FormattedValue']
     
    3. Cross check function in both formload event and javascripts. based on shared code it seems correct. But please cross check. Also, you can try by giving different function name.

    Thank You,
    Pradeep Rai.

  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at
    RE: When i am trying to get the status of the record from lookup using the below script on form load i am facng an issue. Please help me what i can do to resolve the issue.

    Hi Manth,

    The status field has two parts: Lalel and value.

    pastedimage1672883912334v2.png

    The code 'var res = result.statecode().getValue();' got the value, but 'active' is label, and you compared value and label in your code:if(res == "active")

    As I recommended in your previous post, you can use Dataverse REST Builder tool to build api code easily:

    https://github.com/GuidoPreite/DRB 

    https://www.theblueflamelabs.com/lets-utilize-dataverse-rest-builder-to-create-a-web-api-for-dynamics-365-ce/ 

    pastedimage1672883530317v1.png

    Or you can refer to my following code:

    Xrm.WebApi.retrieveRecord("account", "312d3ec5-bf71-ed11-9561-000d3a338355", "?$select=statecode").then(
    function success(result) {
    console.log(result);
    // Columns
    var accountid = result["accountid"]; // Guid
    var statecode = result["statecode"]; // State
    var statecode_formatted = result["statecode@OData.Community.Display.V1.FormattedValue"];//label
    },
    function(error) {
    console.log(error.message);
    }
    );

    Result:

    pastedimage1672884055216v3.png

    ==========

    So you have two directions to change your code:

    1.Use label:

    var res = result["statecode@OData.Community.Display.V1.FormattedValue"];
    if(res == "Active")

    2.Use value:

    var res = result["statecode"];
    if(res == 0)

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 179 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 61 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans