In this video, learn how to use JavaScript in Dynamics 365 CRM to dynamically set a field as required during the OnLoad event of a form. We demonstrate how to check if the form type is ‘Create’ and make the field mandatory while keeping it optional for other scenarios. Enhance your Dynamics 365 customization skills with this step-by-step tutorial!
Code- function setFieldRequiredOnCreate(executionContext) {
// Get the form context
var formContext = executionContext.getFormContext();
// Check the form type (Create = 1)
if (formContext.ui.getFormType() === 1) {
// Set the field as required
formContext.getAttribute(“your_field_name”).setRequiredLevel(“required”);
} else {
// Set the field as not required
formContext.getAttribute(“your_field_name”).setRequiredLevel(“none”);
}
}
This video consists of:
00:00-00:20 Introduction
00:20-01:12 Use case
01:12-03:33 JavaScript code Writing
03:33-04:38 Web Resource Upload and add JS on load event
04:38-05:36 Testing the code
#microsoftsoftware #microsoft #dynamics365 #microsoftdynamics365 #microsoftdynamics365businesscentral #techtutorial #tutorial #dataverse #dynamics365crm #javascript #javaprogramming #powerapps #powerautomate #javatutorial #javascripttutorial #test #java
source