Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JS conversion

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
    Justinjose 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
    Manju Augustine 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
    keyur7379 900 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
    Alex Fun Wei Jie 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans