Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve the value selected in optionset field and display ita value in a text field [closed]

Could any one please help me in displaying an optionset field value in a text field..? I want to retrieve the value selected in optionset and display the same in a text field using plugin.. Iam writing this plugin on "update" of "case' entity...

like image 351
user3518716 Avatar asked Apr 29 '14 08:04

user3518716


People also ask

How can I get option set value in plugin?

Try going to the advanced find and search for all records where tj_status is empty. If you get anything in the results, those are the records on which your code is failing.

How do I get and set the option set value in plugin in CRM?

In plugins you can write yourEntity. yourAttribute = new OptionSetValue(INDEX); The INDEX is an int you can look up in your optionset editor (default values are several digit long). Save this answer. Show activity on this post.

How to get OptionSet value in c#?

For getting the option set value: int value = ((OptionSetValue)entity["yourattributename"]).


2 Answers

For getting the option set value:

int value = ((OptionSetValue)entity["yourattributename"]).Value;

For getting the text:

String text = entity.FormattedValues["yourattributename"].ToString();

In the above code entity is the Entity object from which the optionset value/text to be retrieved. Please replace the attribute name with your case.

like image 124
Renjith Avatar answered Oct 15 '22 12:10

Renjith


You should put this logic in the pre-update (and maybe pre-create) steps. Retrieve the case from the Target parameter, get the display value of the option set field (there are several ways to do this, I like using the FormattedValues attribute), and set the text field to be this value.

entity["new_textfield"] = entity.FormattedValues["new_optionset"];
like image 2
Zach Mast Avatar answered Oct 15 '22 13:10

Zach Mast