Announcements
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.
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.
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 ‘’
1.Go Power Automate(https://us.flow.microsoft.com/en-us/ ) to create an instant vflow.
2.Trigger- Manual:
3.Action- Perform an unbound action using the Common Data Service (current environment).
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.
(2)Result:
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.
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.
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.
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.
updated my previous post
It is showing file not found
edit the field like this screenshot
click on the +, enter name and value, save and publish
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
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.
Thanks for responding on my question!
what is field definition can you explain in brief with example?
André Arnaud de Cal...
293,289
Super User 2025 Season 1
Martin Dráb
232,068
Most Valuable Professional
nmaenpaa
101,156
Moderator