Skip to main content

Notifications

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

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: JS conversion

    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

  • Suggested answer
    Manju Augustine Profile Picture
    140 on at
    RE: JS conversion

    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
    keyur7379 Profile Picture
    902 on at
    RE: JS conversion

    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
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: JS conversion

    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.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans