Read Optionset value in Plugin CRM 2011
Hi,
Below is the sample code to read Picklist value (i.e., OptionSet Value) in CRM 2011
if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] isEntity)
{
currEntity = (Entity)context.InputParameters[“Target”];
}
int statusValue = -1;
string statusText=string.empty;
if (currEntity .Attributes.Contains(“statecode”))
{
OptionSetValue optionState = currEntity .Attributes[“statecode”] as OptionSetValue;
statusValue = optionTimesheetState.Value;
statusText = optionTimesheetState.Text;
}
Hope it helps 🙂
Categories: CRM 2011, Plug-Ins
Tags: CRM 2011, OptionSetValue, picklist value, Plugins, statecode, status
Leave a Reply Cancel reply
Stats
- 1,244,585 hits
Translate
Categories
Top Posts
- Power Apps component framework (PCF) - Beginner guide
- [Step by Step] Postman tool to test Dynamics 365 online Web API
- Auto generate new GUID for ‘uniqueidentifier’ column in SQL Table
- [MS Word] The Linked file isn't available
- Useful JScript syntax's – ADX/Dynamics 365 Portals
- Sandbox vs Production Instances – Dynamics 365
- Set “Created On”,” Created By”, “Modified On”, “Modified By” fields using SDK/Data Import/Plug-in – Dynamics 365
- Associate/Disassociate plugin messages in CRM
- [Step by Step] Debug Model Driven and Canvas Apps using 'Monitor' tool
- [Step by Step] Using TypeScript in Dynamics 365 9.x
Great it is working ….
Thanks, it works 🙂
Thanks for your post but I don’t find The “Text” method…
I’m also receiving the “does not contain a definition for ‘text'” error. What am i missing?
Me too I have the same issue with Text. Did you find a solution please?
Here is a very good solution to retrieve optionSet Text when you have the value and vice versa : https://community.dynamics.com/crm/b/mshelp/archive/2012/06/12/get-optionset-text-from-value-or-value-from-text.aspx
Hi,
There are two way to get text of OptionSet:-
First:-
OptionSetValue opProductType = new OptionSetValue();
opProductType = (OptionSetValue)item.Attributes[attributeName];
var optionValue = opProductType.Value;
Second:-
var StatusString = TermAndCon.FormattedValues[attributeName].ToString();
Post OptionSet Value : –
newSalesOrder[attributeName] = new OptionSetValue(Convert.ToInt32(optionValue));