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 :
Microsoft Dynamics CRM (Archived)

JavaScript Banner

(0) ShareShare
ReportReport
Posted on by 49

Hello everyone!

I would like to utilize Xrm.Page.ui.setFormNotification to display a banner at the top of a "Shipment" record. This banner would only appear for "Shipments" where the related entity Account is classified as "Service Watch".

I'm pretty new to Javascript so I'm a bit lost how to pull values from related entities of a record to use.  Any help would be appreciated! 

*This post is locked for comments

I have the same question (0)
  • Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at
    RE: JavaScript Banner

    You are right. Here is the complete code after corrections. Please test and let me know the response

    function serviceWatchCheck() {

    //execute the query and get the results

    var accountId;

    if (Xrm.Page.data.entity.attributes.get("fieldname").getValue() != null) {

    accountId = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;

    }

    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=cmm_servicewatch").then(function (result) {

    //Show the warning message

    if (data["cmm_servicewatch"] != null && data["cmm_servicewatch"]=="Yes")

    {

    var message = “This Account Is Under Service Watch”;

    var type = “WARNING”; //INFO, WARNING, ERROR

    var id = “123”; //Notification Id

    var time = 5000; //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    }

    }, function (error) {

    //show error message if something error occured during operation

    var message = error.message;

    var type = “ERROR”; //INFO, WARNING, ERROR

    var id = “213”; //Notification Id

    var time = 5000; //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    });

    }

  • PeterJK Profile Picture
    49 on at
    RE: JavaScript Banner

    Like this?

    Like this?

    function serviceWatchCheck() {

    //execute the query and get the results

    var accountId;

    if (Xrm.Page.data.entity.attributes.get("fieldname").getValue() != null) {

    accountId = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;

    }

    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=cmm_servicewatch").then(function (result) {

    //Show the warning message

    if (data["cmm_servicewatch"] === null && data["cmm_servicewatch"]==="Yes")

    {

    var message = “This Account Is Under Service Watch”;

    var type = “WARNING”; //INFO, WARNING, ERROR

    var id = “123”; //Notification Id

    var time = 5000; //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    }

    }, function (error) {

    //show error message if something error occured during operation

    var message = error.message;

    var type = “ERROR”; //INFO, WARNING, ERROR

    var id = “213”; //Notification Id

    var time = 5000; //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    });

    }

  • Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at
    RE: JavaScript Banner

    Put this code in your function at first place

    var accountId;

    if (Xrm.Page.data.entity.attributes.get("fieldname").getValue() != null) {

              accountId = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;

    }

  • PeterJK Profile Picture
    49 on at
    RE: JavaScript Banner

    Pardon the ignorance here, but how would I implement that into the code above?

  • Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at
    RE: JavaScript Banner

    Because you are not passing the accountId and this is undefined in the function. You have to retrieve the accountId from the lookup value of account

  • PeterJK Profile Picture
    49 on at
    RE: JavaScript Banner

    Naveen

    I created a Web Resource, input your Jscript into it, then created an onLoad event for the form referencing the function.

    After publishing, I get an undefined error prompt on form load.  Here is what I used,  not sure if I'm using the correct values:

    function serviceWatchCheck() {

    //execute the query and get the results

    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=cmm_servicewatch").then(function (result) {

    //Show the warning message

    if (data["cmm_servicewatch"] === null && data["cmm_servicewatch"]==="Yes")

    {

    var message = “This Account Is Under Service Watch”;

    var type = “WARNING”;  //INFO, WARNING, ERROR

    var id = “123”;  //Notification Id

    var time = 5000;  //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    }

    }, function (error) {

    //show error message if something error occured during operation

    var message = error.message;

    var type = “ERROR”;  //INFO, WARNING, ERROR

    var id = “213”;  //Notification Id

    var time = 5000;  //Display time in milliseconds

    Xrm.Page.ui.setFormNotification(message, type, id);

    });

    }

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at
    RE: JavaScript Banner

    Hello Peter,

    You can make use of below code snippet to show alert based on related entities record value. You only need to pass the account id which will you get from accounts lookup field:

    function showAlertOnAccountClassified() {
    //execute the query and get the results
    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=servicewatch").then(function (result) {
    //Show the warning message
    if (data["servicewatch"] != null && data["servicewatch"]=="desiredValue")
     {

    var message = “Your message here.”;
    var type = “WARNING”;  //INFO, WARNING, ERROR
    var id = “123”;  //Notification Id
    var time = 5000;  //Display time in milliseconds
    Xrm.Page.ui.setFormNotification(message, type, id);

    }

    }, function (error) {

    //show error message if something error occured during operation

    var message = error.message;
    var type = “ERROR”;  //INFO, WARNING, ERROR
    var id = “213”;  //Notification Id
    var time = 5000;  //Display time in milliseconds
    Xrm.Page.ui.setFormNotification(message, type, id);


    });
    }

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: JavaScript Banner

    Hi Peter,

    Either using crm rest-builder you can retrieve account entity value in CRM javascript or else you can use Xrm.WebApi library method to retrieve account record.

    please refer below url for more info:

    carldesouza.com/.../

    ashwaniashwin.wordpress.com/.../

    carldesouza.com/.../

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans