Most Used Plugin Syntax in Dynamics 365 CRM

We always get requirement which can not be possible using OOB features of CRM and hence we move to the plugin to achieve such requirements.

Whenever we need to retrieve field value from plugin, we always check whether field contains value or not by using if else block or ternary operator which makes code lengthy and not readable.

In this blog, we will see how to efficiently retrieve field values of different data types.


//Single Line Of Text {Defualt Value = null}
string businessWebsite = account.GetAttributeValue<string>("new_website");
Console.WriteLine($"Single Line Of text : {businessWebsite}");

//get optionset text
string cohort = account.Attributes.Contains("new_type") ? account.FormattedValues["new_type"] : "";

//Optionset {Defualt Value = null}
int? customerCohort = account.GetAttributeValue<optionsetvalue>("new_type")?.Value;

//currency {Defualt Value = null}
int? mostRecentACR = (int?)account.GetAttributeValue<money>("new_totalrevenue")?.Value;

//Two option {Defualt Value = false}
bool sdsGradReassign = account.GetAttributeValue<bool>("new_issharedaccount");

//Default Value = null
OptionSetValueCollection language = user.GetAttributeValue<optionsetvaluecollection>("csm_languagessupported");
  if (language != null)
  {
   foreach (var options in language)
   {
    int i = options.Value;
    Console.WriteLine($"Value : {i}");
   }
  }

Comments

Popular posts from this blog

Accessing Fields on QuickView Form through javaScript

ADF - (Part 2) Integrate Data From CRM to External system

Power Apps Portals - Lock/Unlock User Account for Invalid Sign In Attempt