Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / When i am trying to ge...
Sales forum
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.

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

Categories:
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju 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)

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 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
    RodRodriguez Profile Picture
    RodRodriguez 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
    a33ik Profile Picture
    a33ik 84,319 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.

    Hello,

    Try to replace line

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

    with line

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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans