Posts

Showing posts with the label Plugins

Most Used Plugin Syntax in Dynamics 365 CRM

Image
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.GetAttr...

Get option-set value from text and get option-set text from Value using plugin

Image
In this blog we will discuss the use of StringMap table to get option-set metadata in our CRM plugin. StringMap table holds the metadata information of option-sets. The StringMap table contains the following important columns: "Value": This column stores the string value assigned to each picklist option. "AttributeName": This column contains the logical name of the attribute associated with the picklist values. "AttributeValue": This column stores the numeric value assigned to each picklist option. Numeric value assigned to picklist option is unique. "ObjectTypeCode": Object type code of entity for which attribute belongs. Code snippet to get option-set Value from Text: static int? GetOptionSetValueFromText(IOrganizationService service, string optionSetSchemaName, string optionSetText, int objectTypeCode) { string fetch = @"<fetch> <entity name='stringmap' > <attribute name='value' /> <attribut...

Use of aggregate, groupby in fetchxml query

In Microsoft Dataverse, FetchXML  includes grouping and aggregation features that let you calculate sum, average min, max and count. groupby is used to get data from CRM and group it based on particular field value. To use group-by we need to use aggregate. e.g.; If we want to get group accounts based on country and we want count of those country in descending order then we will use fetchXML like below in c#. string accountNumber = "ANO10052023"; string fetchXML = @"<fetch aggregate='true' distinct='false' mapping='logical'> <entity name='account'> <attribute aggregate='countcolumn' alias='country_count' name='new_country'> <attribute alias='new_country' groupby='true' name='new_country'> <order alias='country_count' descending='true'/> <fi...