Skip to main content

Notifications

Announcements

No record found.

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.

  • Diego Botta Profile Picture
    Diego Botta 15 on at
    RE: Multi Select Option Sets array to string

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

  • PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Multi Select Option Sets array to string

    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
    Diego Botta 15 on at
    RE: Multi Select Option Sets array to string

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

  • PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Multi Select Option Sets array to string

    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
    Diego Botta 15 on at
    RE: Multi Select Option Sets array to string

    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
    PabloCRP 1,086 on at
    RE: Multi Select Option Sets array to string
    Please try again, I edited the previous post
  • Diego Botta Profile Picture
    Diego Botta 15 on at
    RE: Multi Select Option Sets array to string

    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

  • Verified answer
    PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Multi Select Option Sets array to string

    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
    Diego Botta 15 on at
    RE: Multi Select Option Sets array to string

    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.

  • Suggested answer
    PabloCRP Profile Picture
    PabloCRP 1,086 on at
    RE: Multi Select Option Sets array to string

    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.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,340 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans