Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Regarding Option Set

(0) ShareShare
ReportReport
Posted on by 100

Hello Everyone,

I am adding new value at option set using addOption() method It is working good But same time after adding new value OnLoad() form

I want to save the record with newly created option set value that time it is showing an error,

PFA screenshot for your reference.

And Please suggest approach to solve this issue.

Currently I am using JavaScript for adding option set values.

03736.Error.PNG

  • Suggested answer
    MikeC282 Profile Picture
    2,115 on at
    RE: Regarding Option Set

    Hi bud. Why are you needing to add option values to a option set on the fly? If it's something you need to do constantly I would then suggest replacing an optionset field with a lookup field linked to a custom entity.

    From there you can use javascript to create the entity record and set it to the lookup.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Regarding Option Set

    Hi Pradnya,

    Maybe you can try to use power automate not js to add new value to option sets, which may be easier and work successfully.

    We will use the Common Data Service (Current Environment) connector and the "InsertOptionValue" Perform Unbound action to achieve this.

    www.bythedevs.com/.../add-new-values-to-cds-option-sets-using-power-automate

    For example, I have an local option set named ‘’

    pastedimage1614763303588v1.png

    1.Go Power Automate(https://us.flow.microsoft.com/en-us/ ) to create an instant vflow.

    2.Trigger- Manual:

    pastedimage1614763348956v1.png

    3.Action- Perform an unbound action using the Common Data Service (current environment).

    pastedimage1614763372077v2.png

    pastedimage1614763384592v3.png

    using following json:

    {
      "LocalizedLabels": [
        {
          "Label": "@{triggerBody()['text']}",
          "LanguageCode": 1033,
          "IsManaged": false,
          "HasChanged": null
        }
      ],
    
      "UserLocalizedLabel": {
        "Label": "@{triggerBody()['text']}",
        "LanguageCode": 1033,
        "IsManaged": false,
        "HasChanged": null
      }
    }

    Test:

    (1)Run the flow.

    pastedimage1614763398649v4.png

    (2)Result:

    pastedimage1614763433020v5.png

    Note: the option sets i test is global, if your option sets is local, you can refer following screenshot:

    Filling AttributeLogicalName and EntityLogicalName, other setting is same.

    pastedimage1614763446595v6.png

    In my example, trigger is ‘manually trigger a flow’, you can set other trigger based on your need, if you still don’t know what trigger you need use, you can describe detailed Scenario.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Suggested answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Regarding Option Set

    you should not do that in JavaScript because the capability to add new options inside an optionset is given to system administrators/system customizers (with an exception when doing data import in some conditions)

    normal users are not able to add an option. if you need users to be able to add dynamically entries, maybe you need to switch your logic to a custom entity instead of an optionset.

  • Pradnya Wankhade Profile Picture
    100 on at
    RE: Regarding Option Set

    Thanks Guido Preite for responding on my post!

    See the given approach in image is correct.

    But what if I want to add the runtime option in option set.

    What should be the approach for that using JavaScript.

    Please suggest me the approach so I can implement for the same.

  • Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Regarding Option Set

    updated my previous post

  • Pradnya Wankhade Profile Picture
    100 on at
    RE: Regarding Option Set

    It is showing file not found

  • Suggested answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Regarding Option Set

    edit the field like this screenshot 

    click on the +, enter name and value, save and publish

  • Pradnya Wankhade Profile Picture
    100 on at
    RE: Regarding Option Set

    Thanks for replying!

    So, how can I add D with value in Option set if it is not available, Please suggest me example so I can add that data in my option set

  • Suggested answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Regarding Option Set

    open the field inside the solution and you see all the values (for example A,B and C with values 1,2 and 3)

    in your JS you can't add D with value 4 because you don't have D with value 4 inside the field definition.

  • Pradnya Wankhade Profile Picture
    100 on at
    RE: Regarding Option Set

    Thanks for responding on my question!

    what is field definition can you explain in brief with example?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,289 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,068 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans