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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript alert based on option set value

(0) ShareShare
ReportReport
Posted on by

Hi all,
I want an alert message to popup when a user opens a contact record, if an option set field on the form is set to certain values. If it is blank, I don't want the alert to appear at all. Eg:

Value 1 - show alert

Value 2 - show alert

blank - no alert

Would anyone be able to help me out with the JS for this? I'm on CRM 2011 on-prem, RU11.

Thanks very much,

Rich

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you need to attach a javascript in your onload event, for example:

    function showAlert(){
    var optValue = Xrm.Page.getAttribute("myoptionset").getValue();
    if (optValue == 10000001) {
       alert("message 1");
    }
    if (optValue == 10000002) {
       alert("message 2");
    }
    }
  • Suggested answer
    Mithilesh Kumar Profile Picture
    10,047 on at

    Hi Rich,

    Here is the JScript Code to run on the OnLoad event of the form. This will check the Text part of your Option Set.

    function AlertOptionSetDisplayValue() {
     var objDisplayValue = Xrm.Page.data.entity.attributes.get("address1_addresstypecode");
     if(objDisplayValue != null){
      DisplayValue = objDisplayValue.getText();
      if(DisplayValue == "ABC"){
       alert(DisplayValue);
      }
     }
    }

    Hope that helps

    Thanks

  • Suggested answer
    PS Profile Picture
    23,577 on at

    Hi there,

    You can take an idea from this:

    function checkblk()

    {

    if(Xrm.Page.getAttribute("attribute1").getValue()!="null")

    {

    var blk=Xrm.Page.getAttribute("new_blacklistedinformation").getValue();

    if(blk=="1")

    {

    alert("Are you sure, you want to punch an order for this customer ?");

    }

                    var st=Xrm.Page.getAttribute("bis_supporttype").getValue();

                    if(st=="1")                

                    {

                           alert("This customer has - Standard Support");

                    }

            }

    }

  • Community Member Profile Picture
    on at

    Perfect -thanks!!

  • srinivascrm Profile Picture
    30 on at

    I am trying to set the firstnames to optionset using the below :

    GetFirstname = Xrm.Page.getControl("new_firstname");
    GetFirstname.addOption({ text: value.firstname, value: key });

    The above is adding all the desired firstnames to the optionset. But, when I am selecting any firstname , it is not displayed .

    Any help ?

  • gkinstler Profile Picture
    on at

    Thank you all for posting this!  This was a big help.

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

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans