In account entity create PO(purchase order) required - two option set field, while create of case or update of case on customer field, if account PO required is yes the make contact field mandatory in Case entity.


For this we need to understand the requirement. we need to write code in JavaScript to achieve this.

Step1: Fist create the Purchase order field in account i.e. Two option set.

Step2: Write the plugin to retrieve the record data based on the lookup in case

Step3: Check that PO status, if the yes then customer filed set as required, if no clear the error message and clear the required filed on customer

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=cr8d7_purchaseorder").then(

function success(result) {

console.log(result);

var purchaseorder = result["cr8d7_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 {

// Xrm.Page.getControl("primarycontactid").clearNotification();

// formContext.getAttribute("primarycontactid").fireOnChange();

return;

    }

}

For this account purchage order is no then Contact is set as not required

Below image po is No So Contact As Not required



Here Po is Set As Yes so
So Contact set As required




Comments

Popular posts from this blog

create HTML page show all contact related to specific account, add this webresource as a subgrid in the form

Connect MS Crm To Postman For Webapi Calls.

create one PCF control and embed into crm