Skip to main content

Notifications

Announcements

No record found.

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
  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,202 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans