web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Option set field in dynamics 365

(0) ShareShare
ReportReport
Posted on by 1,085

Hello Community Experts,

As i have to populate 100's of options in the option set field, I was wondering if there is any way where i can pass values to option set using code, so that it should be reusable in other projects.

Kindly guide,

Best Regards,

Sumaira Noor

I have the same question (0)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    You could use C# to insert new options to option set field.

    1.Create a console app project and connect to Dynamics 365.

    https://arunpotti.wordpress.com/2018/02/03/step-by-step-to-connect-dynamics-365-crm-online-v9-x-using-c-console-application/

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/xrm-tooling/sample-simplified-connection-quick-start

    2.Add options to the option set field.

    // Create a request.
    InsertOptionValueRequest insertOptionValueRequest =
        new InsertOptionValueRequest
    {
        AttributeLogicalName = "new_picklist"//field name
        EntityLogicalName = Contact.EntityLogicalName,//entity name
        Label = new Label("New Picklist Label"_languageCode)//label
    };
    // Execute the request and get the value.
    int insertOptionValue = ((InsertOptionValueResponse)svc.Execute(
    insertOptionValueRequest)).NewOptionValue;


    Console.WriteLine("Created {0} with the value of {1}.",
    insertOptionValueRequest.Label.LocalizedLabels[0].Label,
    insertOptionValue);

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.insertoptionvaluerequest?view=dynamics-general-ce-9

    BTW, adding 100 options is a very heavy work and it is also not easy to find the option you want in the 100 options without searching feature.

    I suggest that you could use Look up Field insead, you just need to create another new entity and build a 1:N relationship between the main entity and the new custom entity.

    pastedimage1574746412317v1.png

    As you can see in the picture, yo could use filter or searching feature in the lookup field which makes it easier to find a special record.

    https://docs.microsoft.com/en-us/dynamics365/sales-professional/use-lookup-fields-forms

    Hope it helps.

    Best Regards,

    Leo

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    If you can, create it as a global optionset and then you can use it for other entities as well...You cn also add it to a solution, export it and keep it safe to use it on any other projects...

    Ideally, for this kind of scenario, you should have gone for reference entity instead of optionset.

    Hope this helps.

  • Sumaira Noor Profile Picture
    1,085 on at

    Thanks for the response Leo and Ravi, but my option set fields are dependent. & I'm not getting what approach to use.

    Best Regards,

    Sumaira Noor

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    What does the "option set fields are dependent" mean? Could you kindly share more details?

    Best Regards,

    Leo

  • Verified answer
    erhan.keskin Profile Picture
    2,253 on at

    Hi,

    If you are looking how to create 100 options quickly, you can use Import functionality of Dynamics, it would create options you have in a file and don't have in the system.

    If you want to use the same Option Set for different fields, you can create a Global Option Set and reuse it anytime you want in a new field.

    Regards,

  • Sumaira Noor Profile Picture
    1,085 on at

    Thanks Leo, Ravi, Erhan for the response

    I have a field B which is dependent on field A for Values to be displayed

    Best Regards,

    Sumaira Noor

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    If so, you could use DependentOptionSetsSample function to manage and configure your option set depedency.

    You could refer to my another answer.

    community.dynamics.com/.../dynamics-365-sdk

    Hope it helps.

    Best Regards,

    Leo

  • Sumaira Noor Profile Picture
    1,085 on at

    Thanks Leo for the response

    Actually i tried that, since i had to list out all the states and countries, i'm looking for a better way where i can store all the states and countries and reuse that code in other environment or to other entities.

    Best Regards,

    Sumaira Noor

  • Suggested answer
    Roma Gupta Profile Picture
    725 on at

    Hi Sumaira

    Going thru earlier discussions, I would suggest to create a new custom config entity, having states & countries mentioned. You can easily then do a data import for x number of countries.

    This way you could have extra country/state info stored and it will be re-usable too.

    Other way round is to use global option sets & then user JavaScript for creating dependencies.

    Regards

    Roma

  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Unfortunately, as far as I konw, there is no other easier way to do this.

    Best Regards,

    Leo

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 180

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 58 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 52 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans