Posts

Showing posts from October, 2021

jQuery Basic Syntax

 In Microsoft D365, jQuery is mostly used in different CRM portal for development purpose. Providing basic syntax required to Get/Set field value in jQuery :  1. TextField :  var firstname = $("#firstname").val();  //get var lastname = $("#lastname").val("Tendulkar");  //set  2. OptionSet :  var type = $("#typecode").val(); //get var type = $("#typecode").val(16350000);  //set (enter code of optionset field) 3. Lookup :  //Get Lookup Value var lookupGUID = $(“#new_accountid”).val(); var lookupValue = $(“#new_ accountid_name”).val(); var entityName= $(“#new_accountid_entityname”).val(); //set Lookup Value $(“#new_accountid”).val(lookupId); $(“#new_accountid_name”).val(lookupName); $(“# new_accountid_entityname”).val(EntitySchemaName); 4. CheckBox :  //Get Checkbox value var isChecked = $(“#{field_name}”).is(“:checked”); if (isChecked == true) { alert(“Checked!”); } else if (isChecked == false) { alert(“Unchecke

Trigger Workflow Using JavaScript

 In Microsoft Dynamics 365, we can trigger the workflow based on OOB condition(eg. record is created or on change of field, etc). If we want to trigger the workflow on specific condition which is not present as a OOB then we can use JavaScript to trigger the workflow. You can follow following code for executing workflow using JavaScript: ExecuteWorkflowUsingJS: function(executionContext) { var formContext = executionContext.getFormContext(); var ExecuteCustomWorkflowRequest = function(entityID, WorkflowID) { this.EntityId = { "guid": entityID }; this.entity = { id: WorkflowID, entityType: "workflow" }; this.getMetadata = function() { return { boundParameter: "entity", parameterTypes: { "entity": { "typeName": "Microsoft.Dynamics.CRM.workflow",

Web API for Create, Update, Delete record

  1. Create Web API Request :  Syntax:  Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback); //json object var entity = {}; entity.address1_country = "India"; entity["areaid@odata.bind"] = "/areas(0b4ecbb5-e574-eb11-a812-0022481a9090)"; //lookup field Xrm.WebApi.online.createRecord("account", entity).then( function success(result) { var newEntityId = result.id; }, function(error) { Xrm.Utility.alertDialog(error.message); } ); 2. Update Web API Request :  syntax :  Xrm.WebApi.updateRecord(entityLogicalName, id, data).then(successCallback, errorCallback); //json object var entity = {}; entity["areaid@odata.bind"] = "/areas(0b4ecbb5-e574-eb11-a812-0022481a9090)"; //lookup field entity.address2_country = "India"; Xrm.WebApi.online.updateRecord("account", "0b4ebjb5-e574-eb11-a812-0022481a9090", entity).then( function success(re

Query Data Using Web API

Sometimes you need to retrieve the data of different entity using javaScript and use that data to perform some business logic. For this Purpose you can use either XmlHttp request or Web API request. In this blog we will see how to retrieve the single record using Web API 1. Retrieve Single Record Using Web API :  Parameters used in webApi to retrieve single record are :  1. Entity logical name,  2. Guid of record,  3. columns which needs to retrieve from that record. Xrm.WebApi.online.retrieveRecord("account", "0b4ecbb5-e574-eb11-a812-0022481a9090", "?$select=address1_city,address1_country").then( function success(result) { var address1_city = result["address1_city"]; var address1_country = result["address1_country"]; //perform your business logic here }, function(error) { Xrm.Utility.alertDialog(error.message); } ); You can get GUID of record which needs to retrieve using lookup field p

Check Dirty Fields or Forms in Dynamics 365

 In Dynamics 365, sometimes there is requirement to check if field value/form is changed or not. In that case we can use getIsDirty Client API reference which will return value true if field or form value is changed. Syntax: formContext.data.entitygetIsDirty();   //Form is dirty formContext.data.entity.attributes.get(arg).getIsDirty();  //field is Dirty To get the list of attributes that have been modified in this session, you can check the IsDirty of the attribute :  getListOfDirtyAttributesOnForm: function(executionContext) { var formContext = executionContext.getFormContext(); var AccountAttribute = formContext.data.entity.attributes.get(); if (AccountAttribute != null) { for (var i in AccountAttribute) { if (AccountAttribute[i].getIsDirty()) { listOfAttributes += AccountAttribute[0].getName() + ", "; } } } }

Accessing Fields on QuickView Form through javaScript

QuickView form is template to view information about related entity record within a form for another entity record. Sometimes you need to access data from QuickView form for performing business logic. In order to get QuickView form in js you can use following syntax :  Syntax :  formContext.ui.quickForms.get(arg); Following is the example how you can access field from QuickView Form :  getAttributeValueFromQuickViewForm: function(executionContext) { var formContext = executionContext.getFormContext(); var quickViewControl = formContext.ui.quickForms.get("quickFormName"); if (quickViewControl != undefined) { if (quickViewControl.isLoaded()) { //not necessary to use this condition quickViewControl.getControl("new_name").getAttribute().setValue("Abhishek Dhandare"); //to get value used below syntax quickViewControl.getControl("new_type").getAttribute().getValue(); //perform your