Friday, 31 August 2018

Useful MS CRM SDK plugin and workflows code

Optionset

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

For getting the option set text:
string text = entity.FormattedValues["attributename"].ToString();

LookUp

For assigning the lookup value:
entity["attributename"] = new EntityRefrence(entity.LogicalName,entity.Id);
eg: to set Account lookup in Opportunity
oppty["accounted"] = new  EntityRefrence("account".account.Id);


For getting the lookup value:

Guid value = ((EntityRefrence)entity.Attributes["attributename"]).Id;


For getting the lookup text:
string text = ((EntityRefrence)entity.Attributes["attributename"]).Name;

No comments:

Post a Comment

Have you ever faced an issue where you need to import some record without changing GUID of the record? For example if we need to migr...