Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Option set field in dynamics 365

(0) ShareShare
ReportReport
Posted on by 1,075

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

  • LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Option set field in dynamics 365

    Hi partner,

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

    Best Regards,

    Leo

  • Suggested answer
    Roma Gupta Profile Picture
    Roma Gupta 725 on at
    RE: Option set field in dynamics 365

    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

  • Sumaira Noor Profile Picture
    Sumaira Noor 1,075 on at
    RE: Option set field in dynamics 365

    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

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Option set field in dynamics 365

    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
    Sumaira Noor 1,075 on at
    RE: Option set field in dynamics 365

    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
    erhan.keskin Profile Picture
    erhan.keskin 2,251 on at
    RE: Option set field in dynamics 365

    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,

  • LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Option set field in dynamics 365

    Hi partner,

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

    Best Regards,

    Leo

  • Sumaira Noor Profile Picture
    Sumaira Noor 1,075 on at
    RE: Option set field in dynamics 365

    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

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Option set field in dynamics 365

    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.

  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Option set field in dynamics 365

    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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans