This blog is for dynamically how we can disable the fields in CRM Using external files based on condition.
I am maintaining all the fields in XML file, which we want to disable, see the below one :
<?xml version="1.0" encoding="utf-8" ?>
<CaseEntity>
<DisableFields>
<name>ags_customer</name>
</DisableFields>
<DisableFields>
<name>ags_casetype</name>
</DisableFields>
<DisableFields>
<name>ags_subcategory</name>
</DisableFields>
<DisableFields>
<name>ags_casepriority</name>
</DisableFields>
</CaseEntity>
I am maintaining all the fields in XML file, which we want to disable, see the below one :
<?xml version="1.0" encoding="utf-8" ?>
<CaseEntity>
<DisableFields>
<name>ags_customer</name>
</DisableFields>
<DisableFields>
<name>ags_casetype</name>
</DisableFields>
<DisableFields>
<name>ags_subcategory</name>
</DisableFields>
<DisableFields>
<name>ags_casepriority</name>
</DisableFields>
</CaseEntity>
Create Web resource with XML type the above one.
Add Javascript with the below one :
function ReadXml() {
alert("Hello");
var xmlPath = "../WebResources/ags_ExternalXMLFile.xml";
$.ajax({
type: "GET",
url: xmlPath,
dataType: "xml",
success: parseXML
});
}
function parseXML(xml) {
$(xml).find("DisableFields").each(function () {
var fieldName = $(this).find("name").text();
var optValue = Xrm.Page.getAttribute("ags_externalsystem").getValue();
if (optValue == 283210000) {
alert("Hi");
Xrm.Page.getControl(fieldName).setDisabled(true);
}
else {
alert("Error");
Xrm.Page.getControl(fieldName).setDisabled(false);
}
});
}
Here, using ajax calling the XML file based on option sets value disabling the fields which are defined in XML file.
Hope it would be useful !!
Happy Coding !!
No comments:
Post a Comment