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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Set Multiselect option field value in single text line of text in ms crm using js

(0) ShareShare
ReportReport
Posted on by

Hi,

Can we set the Mutliselect option field value into a single line of text using javascript in D365 CRM?

Please help if someone has any idea.

Thanks.

I have the same question (0)
  • Suggested answer
    Sergi Valero Profile Picture
    145 on at

    Hello CRMQQ!

    In order to set the values for  a Multiselect option field, you have two ways: 

    1. Using Microsoft Dataverse Web API:

    // On the parameter object, you add the following property:
    {
        "new_multiselectField": "1, 9" 
        // 1 and 9 are the values of the options you want to select, if you just want one, simply add the value of that option
    }

    2. Using formContext

    //You create an array containing the values of the options you want to select
    formContext.getAttribute("new_multiselectField").setValue([100000003, 100000004]);

    Here you also have two guides with more information about the topic: Option 1 (using Web API), Option 2 (using formContext)

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    As per my understanding, you need to set selected options (text) in a single line text field (comma separated).

    Here is the sample code:

    function setOptionsToSomeField(executionContext) {
    
    const formContext = executionContext.getFormContext();
    
    //get the selected options (text)
    var selectedTexts = formContext.getAttribute("gb_multiselect").getText();
    
    //convert selected options to comma seperated string
    
    var stringValue = selectedTexts.join();
    
    // Set this value to a single line text
    formContext.getAttribute("new_sometext").setValue(stringValue);
    
    
    }

    Register this function on change of the Multi-select optionset, and do not forget to pass Execution context as the first parameter.

    Related docs:

    getText (Client API reference) in model-driven apps - Power Apps | Microsoft Docs

    Get and Set Multiselect Option set field values through Javascript | Microsoft Dynamics CRM / 365 (wordpress.com)

    JavaScript Array join() Method (w3schools.com)

  • CRMQQ Profile Picture
    on at

    Thanks!! It gave me expected result.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans