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 CRM (Archived)

Saving the value of a selected optionset where the option set was dynamically built

(0) ShareShare
ReportReport
Posted on by 265

I'm having problems with the following...

I can build a dynamic option set based on an onchange related to another field

unfortunately when the record is saved the option selected is not saved with the record. from what I've been able to determine it has something to do with even though the option set was created it's not really a part of the form.

The issue is that the option set has to be dynamic. I was wondering if I entered the text for each option via the form control (design) but during the onchange where I was building the complete option set  I now just update the values for each option. Would I then be able to save the selected option with the record?

I'm also noticing that anytime I try an Xrm related operation on any of the dynamically added options it acts as if they are not there.

                                                   Xrm.Page.getAttribute("bldgoptions").getSelectedOption().text;

Does not work if the selected option was also one of the dynamically added ones.

 

Thx for any ideas and help.

 

 

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jlattimer Profile Picture
    24,562 on at

    If you check out the example in the SDK for such a scenario, you'll see that the options have already been created through the GUI prior to manipulating them with JavaScript. Similar concept to populating a lookup field, technically through JavaScript you could set any text and guid you wanted and have it show up in the field, but in that case when you went to save it would throw an error instead of saving and losing the value.

    Sample: Create Dependent OptionSets (Picklists)

  • Suggested answer
    Pedro Azevedo Profile Picture
    830 User Group Leader on at

    Hi,

    It's completely dynamic or you have a list of all options? If it's the last option you can add all options in one picklist then you can remove the options that you don't want based in anoher field, check how remove options:

    var optionSet = Xrm.Page.getControl("optionSetName");

    optionSet .removeOption(value);

    Other option is create the option set in server side. Take a look.

  • Lowell Profile Picture
    265 on at

    Thanks, just making sure I understand... The behavior I'm seeing is expected correct? It seems like this was a good fit for what I was trying to do where I build options based on other related data. As I mentioned the options will always be dynamic. I've seen some ideas where they say to populate the options via form design and then remove those not needed. Unfortunately that model won't work here. With all that said is there a better approach?

  • Suggested answer
    Pedro Azevedo Profile Picture
    830 User Group Leader on at

    Hi,

    I take this statement from this thread:

    "Developers should avoid creating new options in script because they may not be valid. The options set in an optionset can be changed or removed. If their code isn't synchronized with the current valid values, developers can introduce bad data. By always beginning witht the collection of valid options, developers know they are always working with valid options. Does this make sense?"

    So in my opinion this behavior is correct, so your option can be a plugin like i refer with a example or you must ask yourself why that field is a picklist and not a Lookup.

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans