Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

addOption value error

Posted on by 160

I'm adding options dynamically.  I have a option set field that have no items.  I'm using javascript to add options on the form onload event.  This is the option set (I added two items to show what the values look like):

pastedimage1573595773631v1.png

This is the code that I'm using to create my option object:

                         
                           var num1 = Number(451330000+ Number(_facs_userid_value);

                           console.log(num1);
                           formContext.getControl("facs_worker1").addOption(setOptionAttributes("Supervisor, Sam"num1));
                           
                           
                           function setOptionAttributes(optionTextoptionVal){
                                      var option = {text:optionTextvalue:optionVal};
                                      return option;
                            }
This is the option value in my picklist:
pastedimage1573595773632v2.png
This is my error:
pastedimage1573595773632v3.png
I'm adding the correct publisher prefix, so I'm not sure why I'm still getting this error.
  • Suggested answer
    Z_Mike Profile Picture
    Z_Mike 160 on at
    RE: addOption value error

    Hi Ravi,

    Thanks for your response.  I now understand the out of range error.

    Mike

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: addOption value error

    Hi,

    You can add options which are already exists. You cannot add any new options which does not exists in the optionset.  The screenshot is not clear but it looks l;ike you have 2 items in your optionset which means you can only add remov these options. Assuming the value for the two items you have added are 802790000, 802790001, you can add/ remove it like this:

    formContext.getControl("facs_worker1").removeOption(802790000)

    formContext.getControl("facs_worker1").addOption(setOptionAttributes("Supervisor, Sam", 802790000));

    You can refer this old thread as well for better understanding.

    community.dynamics.com/.../show-hide-options-in-optionset-value

    Hope this 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans