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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Setting value of Multi Select Option Set using Javascript

(0) ShareShare
ReportReport
Posted on by 35

Hi all,

I'm currently working on a Marketing form that, on submission, should populate a lead and a contact form with the information included in the form. On our original Sales form, we have a Multi Select Option Set that gives the user option of various currencies (GBP, EUR, USD etc) to buy and to sell. However, our Marketing form required an Option Set with a smaller amount of currencies available, written in long form (Pound Sterling, Euros, US Dollars etc). I have therefore created new fields for this purpose, but I need to be able to find a way to map these fields to each other. For instance, should a user select Pound Sterling, the original field should be populated with GBP. I've written the following piece of JavaScript, but it doesn't seem to be working. Can anyone see what the problem is with my code/have any suggestions as to how this can be solved?

function setCurrencySell(executionContext) {
    const formContext = executionContext.getFormContext();
 
 
    //get client type
    // corporate = 126670000
    // private = 126670001
     const clientType = formContext.getAttribute("new_clienttype").getValue();
     if (clientType == 126670001) {
         const currencyYouHave = Xrm.Page.getAttribute("new_CurrencyYouHave").getValue();
         switch (currencyYouHave) {
             case 126670000:
                 formContext.getAttribute("new_currencySell").setValue("126670000");
                 break;
             case 126670001:
                 formContext.getAttribute("new_currencySell").setValue("126670002");
                 break;
             case 126670002:
                 formContext.getAttribute("new_currencySell").setValue("126670001");
                 break;
             case 126670003:
                 formContext.getAttribute("new_currencySell").setValue("126670010");
                 break;
             case 126670004:
                 formContext.getAttribute("new_currencySell").setValue("126670091");
                 break;
             case 126670005:
                 formContext.getAttribute("new_currencySell").setValue("126670076");
                 break;
             case 126670006:
                 formContext.getAttribute("new_currencySell").setValue("126670139");
                 break;
             case 126670007:
                 formContext.getAttribute("new_currencySell").setValue("126670118");
                 break;
             case 126670008:
                 formContext.getAttribute("new_currencySell").setValue("126670163");
                 break;
             case 126670009:
                 formContext.getAttribute("new_currencySell").setValue("126670130");
                 break;
             case 126670010:
                 formContext.getAttribute("new_currencySell").setValue("126670104");
                 break;
             case 126670011:
                 formContext.getAttribute("new_currencySell").setValue("126670083");
                 break;
             case 126670012:
                 formContext.getAttribute("new_currencySell").setValue("126670038");
                 break;
             case 126670013:
                 formContext.getAttribute("new_currencySell").setValue("126670125");
                 break;
             case 126670014:
                 formContext.getAttribute("new_currencySell").setValue("126670040");
                 break;
             case 126670015:
                 formContext.getAttribute("new_currencySell").setValue("126670096");
                 break;
             case 126670016:
                 formContext.getAttribute("new_currencySell").setValue("126670115");
                 break;
             case 126670017:
                 formContext.getAttribute("new_currencySell").setValue("126670056");
                 break;
             case 126670018:
                 formContext.getAttribute("new_currencySell").setValue("126670082");
                 break;
             case 126670019:
                 formContext.getAttribute("new_currencySell").setValue("126670111");
                 break;
             case 126670020:
                 formContext.getAttribute("new_currencySell").setValue("126670134");
                 break;
             case 126670020:
                 formContext.getAttribute("new_currencySell").setValue("");
                 break;
         }
     }
 }
Many thanks,
Emily
I have the same question (0)
  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Setting value of Multi Select Option Set using Javascript

    Hi Emily,

    Is "new_currencySell" the original Multi Select Option Set field?

    pastedimage1592796395088v2.png

    If yes, we should set the field in array format.

    The code below will set one option.

    formContext.getAttribute("new_currencySell").setValue([126670002])

    , and quotation marks are not required.

    You could take this article as reference:

    https://balugajjala.wordpress.com/2018/09/19/get-and-set-multiselect-option-set-field-values-through-javascript/

    Regards,

    Clofly

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 117 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 115

#3
Erin Lubben Profile Picture

Erin Lubben 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans