In account entity create PO(purchase order) required - two option set field, while create of case or update of case on contact field, if account PO required is yes the make contact field mandatory in Case entity.
In account entity create PO(purchase order) required - two option set field, while create of case or update of case on contact field, if account PO required is yes the make contact field mandatory in Case entity.
1. Create a field in account entity, name the filed as purchase order and data type as two Option set.
2. Write JavaScript code to set the contact field as mandatory when Purchase order is true in the account entity.
3. Now create a web resource and paste the JavaScript in it.
4. Open main form of case entity and select the contact field in case entity, select events.
5. Now in events open form library and add web resource.
6. Now open event handler and add function name in it.
Step 1 : Create Purchase order field in account entity , save and publish.
Step 2: JavaScript Code
function Customerlookupincase(executionContext) {
var formContext = executionContext.getFormContext();
var IdofCustomr = formContext.getAttribute("customerid").getValue();
if (IdofCustomr != null) {
Xrm.WebApi.retrieveRecord("account", IdofCustomr[0].id, "?$select=new_purchaseorder").then(
function success(result) {
console.log(result);
var purchaseorder = result["new_purchaseorder"]; // Boolean
if (purchaseorder == 1) {
var field = formContext.getAttribute("primarycontactid");
field.setRequiredLevel("required");
var control = formContext.getControl("primarycontactid");
control.setLabel(control.getLabel() + " *");
}
else {
formContext.getAttribute("primarycontactid").setRequiredLevel("none");
formContext.getAttribute("primarycontactid").fireOnChange();
}
},
function (error) {
console.log(error.message);
}
);
}
else {
return;
}
}
Step 3: Create Web Resource and paste your JavaScript
Step 4: Select Case Entity and Open the main form.
For main form go to entities in Customization and select the case entity , open forms in that search form case main form and select the contact field in case entity.
Step 5: After Selecting The Contact field in case entity then select events then field properties will visible. Inside field properties we have two event list
1. Form Libraries
2. Event Handlers
In Form Libraries provide the Web Resource
In Event handler provide the function name of JavaScript and enable pass execution context as first parameter now click on ok.
Step 6: Now Open your CRM and change the purchase order to true in account entity and save it ,open case entity select contact in case entity and save it












Comments
Post a Comment