Posts

Showing posts with the label CRM

Most Used JavaScript Syntax used in MS CRM

In this blog we will see how we can retrieve different data types fields values in MS CRM using JavaScript. Different types of data types in MS CRM: Single Line of Text Option Set (Dropdown) Two Options (Radio Button) Image Whole Number Floating Point Number Decimal Number Currency Multiple Lines of Text Date and Time Lookup  Single or Multiline Field :  var name = formContext.getAttribute("new_name").getValue(); formContext.getAttribute("new_name").setValue(); Option-Set Field :  int value = formContext.getAttribute("new_type").getValue(); var optionsetText = formContext.getAttribute("new_type").getText(); formContext.getAttribute("new_type").setValue(100); //100 will be the optionset value Multi-Select Option-Set Field :  var multiselectValueArr = formContext.getAttribute("new_multiselect").getValue(); formContext.getAttribute("new_multiselect").setValue([100, 200, 300]); Two-Option Field :  var value = formConte

Bulk insert CRM Data into SQL table using sqlbulkcopy

Image
This blog will explain how we can bulk insert any source data [e.g. MS CRM data] into SQL table using C# code. We will follow below steps:  We will create DataTable in C# with same table name and column names of SQL table  Retrieve source data that needs to be retrieved Add retrieved data from source into DataTable Use SQL Connection and sqlBulkCopy to bulk insert source data into SQL First we will create DataTable with same column name available in SQL table For creating DataTable use below syntax: public static DataTable ActionableAudit() { DataTable actionableAudit; // Create a new DataTable. actionableAudit = new DataTable("ActionableAudit"); actionableAudit.Columns.Add(new DataColumn("ChangedOn", typeof(DateTime))); actionableAudit.Columns.Add(new DataColumn("CreatedBy", typeof(string))); actionableAudit.Columns.Add(new DataColumn("CreatedById", typeof(Guid))); return actionableAudit } After creating Dat

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

Open custom page using JavaScript

Image
Custom pages are low code page type within model-driven apps. Custom pages bring the power of canvas apps into model-driven apps. Once we develop any custom page we will get its unique name from solution, that name of page will be used in JavaScript. We can also pass some data to custom page as a parameter which will be used by custom page for further processing. JavaScript snippet to call custom page: function callCustomPage(selectedItems) { var item = selectedItems; let pageInput = { pageType: "custom", name: "new_custompage_bb4a2", entityName: "incident", recordId: item, }; let navigationOptions = { target: 2, width: 400, height: 350, }; Xrm.Navigation.navigateTo(pageInput, navigationOptions) .then(function () { // Handle success }) .catch(function (error) { // Handle error }); } Here we are passing recordId as a additional parameter to custom page. Note: Please make sure to add cus

Customized Word Template in CRM based on selected records

Image
Word Template in Microsoft Dynamics CRM are used for creating word document dynamically for particular record. These documents help businesses visualize the data in CRM in different ways. With Document template, Users can generate standardized Word documents with just one click. Official documentation of using OOB word template -  Word Template There are certain limitations to the OOB word template provided by Dynamic CRM. e.g., we cannot select particular records from a sub-grid and export only those records in our Word template. To solve this issue, we can create a Word template and use that word template in power automate to populate the data of only selected records. Please follow the below steps to achieve this functionality. 1. Create a Word document template and store it in SharePoint or OneDrive:  Open Word Document and insert Table and give header to table, e.g., I have given header as ID and Type.  In second row we want to add sub-grid data based on records selected. So, we w

Add Data Import Status to sitemap of Model Driven App

Image
The Data Import feature of MS CRM helps you to import data in bulk by using an Excel template. Now, when you import Excel data to CRM, CRM provides you with the great feature of observing the data import status immediately in the same window. But what if users want to see their status after some time? Then they need to navigate to advanced settings -> Data Management -> Import This requires a lot of clicking to just see the status of the data import.   To avoid this issue, we will add data import to the sitemap of the model-driven app. You just need to add URL subarea to your sitemap.   Follow below steps to add URL subarea to sitemap 1. Open your model driven app from solution 2. Customize the sitemap 3. Add subarea to your sitemap 4. Select Type as a URL 5. Mentioned below URL to see Data Import Status 6. Give some meaning title like Data Import Status   Format of URL should be like below : /main.aspx?appid=[YourAppID]&pagetype=entitylist&etn=importfile Replace [Your

Customize OOB Subgrid to show records based on dynamic filter criteria

  OOB dynamic CRM subgrids are limited to static filter criteria's only. If we want to add any dynamic filter criteria to filter records on subgrid then it's not possible with normal subgrid configuration. However, we can achieve such requirements by customizing fetchxml of view present on subgrid using JavaScript. eg. If we want to filter accounts on case entity by matching criteria (Current case record Case number = All accounts with matching Account number i.e [case number(case) = account number (account)]) then we can achieve such requirements by using below JavaScript Add below JS on load of case entity. so that on load it will get case number and filter account subgrid dynamically function filterAccountSubgridInCase(executionContext) { var formContext = executionContext.getFormContext(); var gridContext = formContext.getControl("Subgrid_Accounts"); var caseNumber = formContext.getAttribute("new_casenumber").getValue(); //customizing

Custom Subgrid Using HTML Web resource

Sometimes you will get requirement to show records in subgrid without any proper relationship. In such scenario you can go with custom subgrid and show all those related records in HTML table that won't be possible with OOB way of ms crm Below is the sample code for HTML web resource for creating sample custom subgrid Here we are showing all accounts in Case entity where matching criteria is Case Number = Account number(that too without any relationship between Case and account) html><head><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta&g