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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Multi Select Option Sets array to string

(0) ShareShare
ReportReport
Posted on by 15

Hello,
In order to use the values ​​chosen later in a filter of Portal 365 I need to pass the selection in the multiple select option field to a text field.
How could I do it via javascript? I don't understand how to unset the array to make it string

I'm using 9.0 of Microsoft Dynamics 365 CRM on-premise

Thx for any advice.

I have the same question (0)
  • Suggested answer
    PabloCRP Profile Picture
    1,088 on at

    Hi, Diego Botta

    function doSomething(executionContext){
    var formContext = executionContext.getFormContext();
    //Your logic...
    
    var values = getValuesMultiPicklist("new_MY_MULTI_OPTIONS_FIELD",formContext);
    var myTextField = formContext.getAttribute("new_MY_TEXT_FIELD");
    if(myTextField!==null&&values!=="")
        myTextField.setValue(values);
    }
    
    //@parameter in formContext = Xrm context, Xrm.Page
    //@parameter in field = name field, string
    //@values out string 
    function getValuesMultiPicklist(field,formContext = Xrm.Page){
    var values = "";
    var multiOptions= formContext.getAttribute(field);
    if(multiOptions!==null)
        values = multiOptions.getText()?multiOptions.getText().join(","):"";
    return values;
    }

    it returns the label of the selected options, but if you need for the numerical value use .getValue() instead of .getText() in line 17.

    Hope it helps.

  • Diego Botta Profile Picture
    15 on at

    Hi Pablo,

    Sorry that we have to go slower with the explanation, I paste the code as I think it would go with the fields I have:

    multiple pick list:  new_temasdeactividadmpl

    text field: new_inlinetxt

    So the java you shared with me I arranged it like this:
    :jserror.JPG

    And assign the functions to the multiple selection field:

    Asign_E900_.JPG

    but i got an error when i try it on the form.

  • Verified answer
    PabloCRP Profile Picture
    1,088 on at

    If you notice in the function getValuesMultiPicklist you should have 2 parameters, field and  formContext.  just change "new_temasdeactividadmpl" by word -> field

    function doSomething(executionContext){
    var formContext = executionContext.getFormContext();
    //Your logic...
    
    var values = getValuesMultiPicklist("new_temasdeactividadmpl",formContext);
    var myTextField = formContext.getAttribute("new_inlinetxt");
    if(myTextField!==null&&values!=="")
        myTextField.setValue(values);
    }
    
    //@parameter in formContext = Xrm context, Xrm.Page
    //@parameter in field = name field, string
    //@values out string 
    function getValuesMultiPicklist(field,formContext = Xrm.Page){
    var values = "";
    var multiOptions= formContext.getAttribute(field);
    if(multiOptions!==null)
        values = multiOptions.getText()?multiOptions.getText().join(","):"";
    return values;
    }

    and remember to pass the execution context...  mark the checkbox at the time you are registering the function in the form "pass execution context as first parameter"

    note: the new_inlinetxt field must have a considerable maximum length of characters e.g. 100.

    regards.
    please consider marking as an answer if it was helpful
  • Diego Botta Profile Picture
    15 on at

    Thanks for reply,

    I check both thing copy the new code with field and check  pass execution context as first parameter.

    Still getting this both error

    jsfirst.JPGjssecond.JPG

  • PabloCRP Profile Picture
    1,088 on at
    Please try again, I edited the previous post
  • Diego Botta Profile Picture
    15 on at

    is working!

    It just throws me an error but it still does its job as you can visualize on the right
    last-error.JPG

    very grateful for your help

  • PabloCRP Profile Picture
    1,088 on at

    Sorry that's a odd issue, but it's popping up in the MicrosoftAjax.js library. if you disable your custom function does the same error happen?

  • Diego Botta Profile Picture
    15 on at

    Thanks Pablo for staying with me.
    When I delete the custom javascript the error goes away.

  • PabloCRP Profile Picture
    1,088 on at

    Hi, I think the issue could be...
    Look at the screen you posted
    pastedimage1611708314870v1.png

    The function getValuesMultiPicklist shouldn't be registered in the form, it's just for internal purpose so remove it

    pastedimage1611708513100v2.png

    regards.

  • Diego Botta Profile Picture
    15 on at

    Well sir, the problem has been resolved. I hope one day to be here to help you. Thanks a lot

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
#ManoVerse Profile Picture

#ManoVerse 93

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans