Learn JavaScript for D365 CRM
Learn JavaScript for D365 CRM
In this blog we are going to learn how to write javascript to get , set , show , hide,notify, and making field values required or none in d365
if this blog helpful for you please follow and comment below thank you
var formContext = executionContext.getFormContext();
//getting field values
var name = formContext.getAttribute("name").getValue();
//set field values
formContext.getAttribute("name").setValue("New");
//getting lookup values
var accountlookup = formContext.getAttribute("account").getValue();
//set lookup value
accountlookup[0].Id = accountId;
//retrieving values from account lookup and setting values
if (accountlookup != null)
{
Xrm.webAPI.online.service.retieve(accountlookup, accountId, "$select = name,nisl_fullname").then({
function success(result)
{
var fullname = result["name"];
var name1 = result["nisl_fullname"];
formContext.getAttribute("name").setValue(fullname);
formContext.getAttribute("nisl_fullname").setValue(name);
}
})
}
//getting optionset Values
var optionsetValue = formContext.getAttribute("optionsetfield").getValue();
//getting paticular value in optionset
var optionsetValue = formContext.getAttribute("optionsetfield").getValue()[0];
//set Optionset Values
formContext.getAttribute("OPTIONSETFIELD").setValue("100000");
//setting particular value in optionset
formcontext.getAttribute("optionsetfield").setValue("samson");
//getting MultipleoptionsetValues
var multipleoptionset = formContext.getAttribute("Multipleoptionset").getValue()[indexValue];
var multipleoptionset = formContext.getAttribute("Multipleoptionset").getText()[indexValue];
//setting MultipleOptionsetValues
formContext.getAttribute("multipleoptionset").setValue([1000000, 10000001]);
formContext.getAttribute("multipleoptionset").setValue(["sam", "son"]);
//check field mandatory or not //check if field is required or not
//if field is required that without entering values into it it cannot save form
formContext.getAttribute("name").setRequiredLevel("required");
//if field is not required , used in scenario where making required field as not required
formContext.getAttribute("name").setRequiredLevel("none");
//enabling or disabling a field // locking and unlocking field
//enable or disable a field
formContext.getControl("name").setDisabled(true/false);
//show or hide field values
formContext.getControl("name").setVisible(true / false);
// show or hide tabs
Xrm.page.ui.tabs.get("tab_name").setVisible(true / false);
// show or hide sections
Xrm.page.ui.tabs.get("tab_name").sections.get("section").setVisible(true / false);
//enable /disable form
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
var control = Xrm.Page.getControl(attribute.getName());
if (control) {
control.setDisabled(true)
}
});
//save form
Xrm.Page.data.entity.save();
//get Entity Name
var value = Xrm.Page.data.entity.getEntityName();
//get the entity id
var value = Xrm.Page.data.entity.getId();
//open entity form
Xrm.Utility.openEntityForm("entityName");
//alert popup
alert("message");
//Form notification for showing error
formContext.ui.setFormNotification(message, messageType, uniqueId);
//Form Notification
formContext.ui.setFormNotification("Error Message", "Error");
formContext.ui.setFormNotification("Warning Message", "Warning");
formContext.ui.setFormNotification("Info Message", "Info");
//Clear Notification
formContext.ui.ClearNotification(uniqueId);
formContext.ui.clearFormNotification(errorId);
formContext.ui.clearFormNotification(warningId);
formContext.ui.clearFormNotification(infoId);
//get BPF /Processs ID
Xrm.Page.data.process.getActiveProcess().getId();
//get BPF / Process Names
Xrm.Page.data.process.getActiveProcess().getName();
//show or hide process
Xrm.Page.ui.process.setVisible(false / true);
}
Comments
Post a Comment