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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Set OptionSet Text in C#

(0) ShareShare
ReportReport
Posted on by 590

Hi Friends,

Background:

I got a requirement to insert the records from Asp.net application to CRM surface. Some of the fields are OptionList. 

Problem : I need to set the option set text in CRM surface.I don't know the Optionset value.I have only text.

Please help me in this regards,

With Regards,

Datta.G

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    DH kumar CRM Profile Picture
    1,345 on at

    Hi,

    To get optionset value try below code which will give value.

    var myOptionSet = Xrm.Page.data.entity.attributes.get("optionsetattributename");

    var optionSetValue = myOptionSet.getValue();

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Datta,

    The CRM Surface it means CRM Web UI?

    And you mean that your input is Text? But CRM will accept Option Set value, so you need to convert the Text go get the value before you insert the records from your custom ASP.NET app.

    Check this link:

    www.codeproject.com/.../Get-the-OptionsetValue-and-OptionsetText-for-Dynam

    It is in C#.

    But, you need to be aware that the label or text in CRM Option Set can be changed and you need to adjusted to align with your ASP.NET app showing that OptionSet Text. Otherwise when you pass the text, you will not get the integer value from option set value.

    Hope this helps!

    Thanks.!

  • Suggested answer
    Bruno Lucas Profile Picture
    5,421 on at

    [server delay, posted same link as Aileen, therefore, I agree with her]

    the text is a bit more tricky:

    www.codeproject.com/.../Get-the-OptionsetValue-and-OptionsetText-for-Dynam

    this article is for 2011 but same deal for crm 2013

    www.magnetismsolutions.co.nz/.../setting_values_programmatically_via_the_crm_2011_sdk

  • DATTA GUNTURU Profile Picture
    590 on at

    Thank you very much

    Yes, I have text and I don't know the value. Can't I set the selected text directly.

    I can do this process for one field ,but how abt having 50 fields.

    With Regards,

    Datta.G

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Datta,

    No, you cannot. Option set needs key, which is its integer value.

    I can do this process for one field ,but how abt having 50 fields.

    --> Then, you need to call this function:

    public static int getOptionSetValue(string entityName, string attributeName, string  optionsetText)

    50 times for each field or you can modify the function to accept list parameter then you decipher one by one for list members into each attributeName and each optionSetText.

    Hope this helps!

    Thanks.

  • DATTA GUNTURU Profile Picture
    590 on at

    Thank You Very Much Aileen Gusni,

    Could you please tell me how to send all the option list attribute at a time and get back their respective optionsettext in single request.

    With Regards,

    Datta.G

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Datta,

    you can use array or list to list all of the attribute name and optionsetText then you can call the

    getOptionSetValue(string entityName, string attributeName, string  optionsetText)

    function.

    To get the optionsetvalue

  • DATTA GUNTURU Profile Picture
    590 on at

    Hi,

    Its not allowing me to send the collection of attributes, Could you please share some snippet.

    Thanks you in advance.

    With Regards,

    Datta.G

  • Community Member Profile Picture
    on at

    Datta, As I understand from the link provided by Aileen and Bruno, there are two methods with complete code . You can pass the Option set text to retrieve Value.

    Here is the link:

    www.codeproject.com/.../Get-the-OptionsetValue-and-OptionsetText-for-Dynam

    Harihar

  • Mahendar Pal Profile Picture
    45,095 on at

    Can't you store the optionset values in your asp.net dropdown as index it will be easy to use that and update it, instead of making call every time to query index value.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans