Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Pop-up "warning" window for specific records

Posted on by 202

Hi everyone

I've been asked if I can implement some sort of pop-up window that will contain important warning information (e.g. "DO NOT SPEAK TO THIS CONTACT!!") if someone opens a certain contact record in CRM.

Has anyone successfully done this? If so, could you please offer me some tips / a solution?

I'm guessing that the text would need to be stored in a specific field on the Contact Entity which would then be displayed in the pop-up box, but only if the text field contained data of course.

Any help would be much appreciated.

Many thanks
Jon

  • JonClay Profile Picture
    JonClay 202 on at
    RE: Pop-up "warning" window for specific records

    Hi Leco Lv

    Thank you SO much for your help with this. The revised Javascript completely fulfilled my requirements.

    Best wishes

    Jon

  • Verified answer
    Leco Lv Profile Picture
    Leco Lv on at
    RE: Pop-up "warning" window for specific records

    Hi partner,

    Don't worry. there are only two places that need to be modified.

    pastedimage1663125724921v1.png

    function Alert(executionContext) {
        const formContext = executionContext.getFormContext();
        let cr429_alert= formContext.getAttribute("cr429_alert").getValue();
    
         if(cr429_alert != null) {
         var alertStrings = { confirmButtonLabel: "Yes", text: cr429_alert, title: "!!!!!!" };
         var alertOptions = { height: 120, width: 260 };
         Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
          function (success) {
            console.log("Alert dialog closed");
        },
          function (error) {
            console.log(error.message);
        }
    );
       }
    }

  • JonClay Profile Picture
    JonClay 202 on at
    RE: Pop-up "warning" window for specific records

    Hi Leco Lv

    I'm now back from my holidays and have tested the Javascript that you sent me (thank you!).

    The process seems to work OK, but I just have a couple of queries please:

    1. I need to show whatever text is put into the alert field, so it could say anything and not just "DO NOT SPEAK TO THIS CONTACT". What do I need to change in the script in order to achieve this? I assume that I need to change the if(new_alert== part of the script.

    2. The line below this also mentions this text string, so what do I need to do in order to change that too?

    Many thanks once again,

    Jon

  • JonClay Profile Picture
    JonClay 202 on at
    RE: Pop-up "warning" window for specific records

    Hi Leco Lv

    Thank you so much for sending this to me. I'm just about to fly away on holiday for a week, so I'll try this when I get back.

    Many thanks once again.

    Jon

  • Suggested answer
    Leco Lv Profile Picture
    Leco Lv on at
    RE: Pop-up "warning" window for specific records

    Hi partner,

    Here's the details:

    pastedimage1662528161816v1.png

    function Alert(executionContext) {
        const formContext = executionContext.getFormContext();
        let cr429_alert= formContext.getAttribute("cr429_alert").getValue();
    
         if(cr429_alert == "DO NOT SPEAK TO THIS CONTACT") {
         var alertStrings = { confirmButtonLabel: "Yes", text: "DO NOT SPEAK TO THIS CONTACT!!!.", title: "!!!!!!" };
         var alertOptions = { height: 120, width: 260 };
         Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
          function (success) {
            console.log("Alert dialog closed");
        },
          function (error) {
            console.log(error.message);
        }
    );
       }
    }

  • JonClay Profile Picture
    JonClay 202 on at
    RE: Pop-up "warning" window for specific records

    Hi Leco Lv 

    Many thanks for your reply.

    Here is what I'm trying to achieve:

    - not all contact / organisation records will need an alert box to pop up when the record is opened

    - for those that do, I would like an alert box to to pop up each time the record is opened by any user

    - I will create a new text field on the Contact Entity called Warning

    - in the Warning field I will put any text that is required in the pop up (for example. DO NOT SPEAK TO THIS PERSON!)

    - so, if text exists in the Warning field then the Contact / Organisation record should have a pop up alert box showing the contents of the Warning field

    - conversely, if the Warning field is blank then the Contact / Organisation record should not have a pop up alert box showing

    Many thanks
    Jon

  • Suggested answer
    Leco Lv Profile Picture
    Leco Lv on at
    RE: Pop-up "warning" window for specific records

    Hi partner,

        Could  you tell me what the specific conditions are, what conditions need to be met by the contact will be typed into the fields?

  • Suggested answer
    antc Profile Picture
    antc 2,909 on at
    RE: Pop-up "warning" window for specific records

    There is enough information to work it out however you will just need to add this to the code:

    var warning = formContext.getAttribute("new_warning").getValue();

    if(warning != null)

    {

      // Do the alert here..

    }

  • JonClay Profile Picture
    JonClay 202 on at
    RE: Pop-up "warning" window for specific records

    Hi there Leco Lv 

    Thanks so much for your reply.

    This seems as though it will definitely work, but I'm not sure how to show the content of a specific field instead of the text "DO NOT SPEAK TO THIS CONTACT!!".

    What I need to do is the following:

    - have a field on the Contact Entity / Contact Form called "Warning" in which I can type a string of text (e.g. "PLEASE BE CAREFUL" or "DO NOT SPEAK TO THIS CONTACT" etc.
    - most Contacts will have no text in this box as most Contacts do not require a warning to be shown on-load
    - the alert box should therefore only show on-load of the Contact if there is text in the "Warning" field

    Do you know if this is possible?

    Many thanks
    Jon

  • Suggested answer
    Leco Lv Profile Picture
    Leco Lv on at
    RE: Pop-up "warning" window for specific records

    Hi partner,

       Both partners above are right. you can add an onload event to the contact table. here's the details:

       Refer link: How to add JavaScript to form on load in Dynamics 365 - Fredrik Engseth

       My example:

       pastedimage1661931585634v1.png   pastedimage1661931811185v2.png

       Save&Publish

       My  codes:

    var alertStrings = { confirmButtonLabel: "Yes", text: "DO NOT SPEAK TO THIS CONTACT!!!", title: "Sample title" };
    var alertOptions = { height: 120, width: 260 };
    Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
        function (success) {
            console.log("Alert dialog closed");
        },
        function (error) {
            console.log(error.message);
        }
    );

      result:

       pastedimage1661932790662v3.png

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

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,576 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,815 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans