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)

JS conversion

(0) ShareShare
ReportReport
Posted on by 1,942

Hi all,

In the below code, selectedValues return the string array of text & values. Before comparing selectedValues in the if condition, how do i separate the number string & convert it to integer?

function SetMultiSelValues(executionContext){
var formContext = executionContext.getFormContext();
var selectedValues = formContext.getAttribute("new_flagreason").getSelectedOption();
if(selectedValues == null){
formContext.getAttribute("iis_flagstatusnew").setValue("0"); //No issues
}
else if(selectedValues == 100000000){
formContext.getAttribute("iis_flagstatusnew").setValue("0"); //No issues
}
else{
formContext.getAttribute("iis_flagstatusnew").setValue("1"); //Issues Exists
}
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    To Get the selected text of a OptionSet field

    Xrm.Page.getAttribute("fieldname").getSelectedOption().text;

    To Get the selected value of a OptionSet field

    Xrm.Page.getAttribute("fieldname").getSelectedOption().value;

    or

    To Get the selected text of a OptionSet field

    Xrm.Page.getAttribute("fieldname").getText();

    To Get the selected value of a OptionSet field

    Xrm.Page.getAttribute("fieldname").getValue();

    Both code will work.

  • Suggested answer
    keyur7379 Profile Picture
    902 on at

    Hi,

    If iis_flagstatusnew this field is two option then you need to pass this way.

    if(selectedValues == null){
    formContext.getAttribute("iis_flagstatusnew").setValue(false); //No issues
    }
    else if(selectedValues == 100000000){
    formContext.getAttribute("iis_flagstatusnew").setValue(false); //No issues
    }
    else{
    formContext.getAttribute("iis_flagstatusnew").setValue(true); //Issues Exists
    }

    Thanks,

    keyur shah.

  • Suggested answer
    Manju Augustine Profile Picture
    140 on at

    Hi Vighnesh,

    In the else if condition please use selectedValues.value instead of using selectedValues.

    function SetMultiSelValues(executionContext){
    var formContext = executionContext.getFormContext();
    var selectedValues = formContext.getAttribute("new_flagreason").getSelectedOption();
    if(selectedValues == null){ 
    formContext.getAttribute("iis_flagstatusnew").setValue("0"); //No issues
    }
    else if(selectedValues.value == 100000000){
    formContext.getAttribute("iis_flagstatusnew").setValue("0"); //No issues
    }
    else{
    formContext.getAttribute("iis_flagstatusnew").setValue("1"); //Issues Exists
    }
    }

    Thanks,

    Manju

    If found useful, please mark the answer as verified.

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi Vighnesh,

    var selectedValues contains text and values. You should explicitly call selectedValues.value for optionset Value and  selectedValues.text or optionset text. 

    function SetMultiSelValues(executionContext) {
      var formContext = executionContext.getFormContext();
      var selectedValues = formContext.getAttribute("new_flagreason").getSelectedOption();
      if (selectedValues == null || selectedValues.value == 100000000) {
        formContext.getAttribute("iis_flagstatusnew").setValue("0");
      } else {
        formContext.getAttribute("iis_flagstatusnew").setValue("1");
      }
    }

    Thanks

    Justin Jose

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