Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

How to set a value of Multi-select Option set field using SOAP Request or XML request ?

Posted on by 215

I need a way to set a value in multi-select option set field using XML request/SOAP request or any code by which I can set a value.

Can anyone suggest me a way to achieve this ?

I want to achieve this using SOAP request or XML request in a proper way.

Thanks in advance.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to set a value of Multi-select Option set field using SOAP Request or XML request ?

    Hello,

    If you want to use SOAP to set field your best friend is soap logger - carldesouza.com/dynamics-365-soap-logger

    Good luck.

  • nickmangioros Profile Picture
    nickmangioros 460 on at
    RE: How to set a value of Multi-select Option set field using SOAP Request or XML request ?

    Hi Leo,

    When passing the function on the OnSave event

    What function are you entering?

    You screenshot says OnSave1 but that is not reference anywhere

    Has anyone gotten this to work?

    Thanks

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set a value of Multi-select Option set field using SOAP Request or XML request ?

    Hi,

    You can use the below code to set value in a multi select OptionSet. In my below code, I am retrieving value from a multi select OptionSet present on the Account form and setting the same value in another multi select OptionSet present on a different form.

    SetMultiSelect = function (executionContext) {

           //Get Form Context from Execution Context

           var formContext = executionContext.getFormContext();

    //Get Account GUID

           var accountId = formContext.getAttribute("new_account").getValue()[0].id;

    //Retrieve the values of multi select OptionSet from Account entity

           Xrm.WebApi.retrieveRecord("account", accountId, "?$select=new_multiselect").then(

              function success(result) {

                  if (result.new_multiselect !== null) {

      //Get Array of Selected OptionSet Values

                      var values = result.new_multiselect;    

      //Convert the retrieved string array into an integer array to set it correctly in another multi select OptionSet

                      var val = values.split(',').map(Number);

                      formContext.getAttribute("new_accountmultiselect").setValue(val);                  

                  }

              },

              function (error) {

                  writeToConsole(e.message);

              });

       }

    To set static values you can also try:

    formContext.getAttribute("new_accountmultiselect").setValue([1,2,3,4]);  

    Hope it helps!

    Thanks

    Hiteksha

  • Milansinh Raj Profile Picture
    Milansinh Raj 215 on at
    RE: How to set a value using SOAP Request / JavaScript for Multiselect Option set field ?

    Actually I want to write a code to set a value in Multiselect option set using SOAP request or XML request.

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: How to set a value using JavaScript for Multi select Option set field ?

    Hi partner,

    Please use the following code.

    function SetMultiSelValues(executionContext) {
        //Get Form Context from Execution Context
        var formContext = executionContext.getFormContext();
    
        //Get Array of Selected OptionSet Values
        //Returns: [100000005, 100000001]
        var existingValues = formContext.getAttribute("new_muliteselectedfield").getValue();
    
        //Append a set of values
        var newValues = [1, 2];
        var updatedValues = ConcatArrays(existingValues, newValues);
    
        //Appends to Existing Selected Values
        //New Values: [100000005, 100000001, 100000003, 100000004]
        formContext.getAttribute("new_muliteselectedfield").setValue(updatedValues);
    }
    function ConcatArrays(existingValues, newValues) {
        if (existingValues === null || Array.isArray(existingValues) === false) {
            return newValues;
        }
    
        if (newValues === null || Array.isArray(newValues) === false) {
            return existingValues;
        }
        return existingValues.concat(newValues);
    }


    I have tried in my environment and it worked well.

    When you add this function into form, remember to select "Pass execution context as first parameter".

    Commun1.PNG

    Hope it helps.

    Best Regards

    Leo

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans