RE: preventDefault not working correctly
HI,
Add below code on onchange of gilm_variation field-
var saveAllowed=true;
function denyCreateVariationSor(executionContext)
{
debugger;
var id = Xrm.Page.getAttribute("gilm_variation").getValue()[0].id;
var url = 'gilmartins-test.crm11.dynamics.com/.../gilm_variations eq ' + id + ')';
var variationStatus;
var formContext = executionContext.getFormContext();
fetch(url).then(response => response.json()).then(data =>
{
var arr = data.value;
variationStatus = arr[0]["gilm_variationstatus"];
if (variationStatus != 870110000)
{
saveAllowed=false;
}
else
{
formContext.data.save()
}
});
}
And then add below code on onsave of your form -
function Form_OnSave(executionContext)
{
if(saveAllowed==false)
{
executionContext.getEventArgs().preventDefault();
alert("You can't add a SOR onto a completed/cancelled variation");
}
}
I hope this works. I am making use of Global variable to achieve the requirement.
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/