JavaScript Code For Beginner In Dynamic CRM
- Check if Object is null or undefine in dynamic DCRM using JavaScript..
checkIfObjectNullAndUndefine: function (obj){
"use strick",
if ((obj ===undefine)|| (obj === null))
{
return true;
}
return false;
};
- Check field has value
checkFieldHasValue(FormContext, fieldName){
//Do Logic here
}
checkFieldHasValue: function (formContext, fieldName)
{
"use strict";
return (checkFieldIsPresent(formContext, fieldName) && !checkIfObjectNullOrUndefined(formContext, formContext.getAttribute(fieldName).getValue()));
};
checkFieldIsPresent: function (formContext, fieldName) {
"use strict";
return !checkIfNullOrUndefined(formContext, formContext.getAttribute(fieldName));
};
Note : Here checkIfNullOrUndefined call above function.
- Remove Curley bracket from GUID Formats like : "{e117dg4b-9686-ed11-81cd-001dd806b77d}" toe117dg4b-9686-ed11-81cd-001dd806b77d.
var guidFormtes = formContext.getAttribute(fieldSchemaName).getValue()[0].id.toLowerCase().replace("{","").replace("}","");
- How to set the lookup field in dynamic CRM using JavaScript.
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = enityWhichToBeSet.entities[0][fieldid];
lookupItem.name = enityWhichToBeSet.entities[0][fieldname"];
lookupItem.entityType = "entityschemaName";
lookupData[0] = lookupItem; formContext.data.entity.attributes.get(schemaName).setValue(lookupData);
- How to use fetch xml query in JavaScript Code.
- Show and Hide the Section
Show :
formContext.ui.tabs.get("Tab_Name").sections.get("Section_Name").setVisible(true);
Hide :
formContext.ui.tabs.get("Tab_Name").sections.get("Section_Name").setVisible(false);
- Show and Hide the tab
Show
formContext.ui.tabs.get("Tab_Name").setVisible(true);
Hide
formContext.ui.tabs.get("Tab_Name").setVisible(false);
- How to filter the JSON record
var jsonConfigurations = [];
filteredRecordOnJsonObject = jsonConfigurations.jsonRecordValueName.filter(d => d.whatWeGotandTryToCompareWithExistingOne === whatWeHaveExsiting);
- How to get current login user id
var loginUserId = Xrm.Utitlity.getGlobalContext().userSettings.userId.replace("{","").replace("}","");
- How to get GUID of the record
var recordId= null;
var recordId = formContext.getAttribute("schemaId").getValue()[0].id
- How to make filed as a required, none, recommended.
None :
formContext.getAttribute("fieldNameOfSchema").setRequiredLevel("none");
Required:
formContext.getAttribute("fieldNameOfSchema").setRequiredLevel("required");
Recommended
formContext.getAttribute("fieldNameOfSchema").setRequiredLevel("recommended");
- How to get the form type
Get Form Type
formContext.ui.getFormType();
If you want to create form
If(formContext.ui.getFormType()===1)
If you want to modified form
If(formContext.ui.getFormType()===2)
If you want to read form
If(formContext.ui.getFormType()===3)
If you want to disable form
If(formContext.ui.getFormType()===4)
If you want to bulk edit on form
If(formContext.ui.getFormType()===5)
Note : All the above form return number. If you add one of the quick create form that form return value 1.
- How to check field is not future date
function checkFieldIsNotFutureDate(fieldValue) {
"use strict";
var CurrentDateToday = new Date();
var futureDate = false;
if (fieldValue> CurrentDateToday) {
futureDate = true;
}
return futureDate;
};
- How to cancelled the save operation but rest of the even handler will work as usual
executionContext.getEventArgs().preventDefault();
Comments
Post a Comment