Hi Noor, please follow the guide here xrmcenter.wordpress.com/.../prevent-save-in-crm-form
you have to add the context as first parameter.
1. Add 1 parameter to your method as below:
function getminimumsalespriceByProductId(context) {
debugger;
var productID = Xrm.Page.getAttribute("productid").getValue();
var priceId = Xrm.Page.data.entity.getId();
var amount = null;
var miniumprice = null;
var amount = null;
var productId = null;
if (product) {
productId = product[0].id;
}
amount = Xrm.Page.getAttribute("amount").getValue();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/ProductSet(guid'" + productID + "')?$select=Name,ProductNumber,new_MinimumSalesPrice,np_minimumsalesprice", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.responseText).d;
var name = result.Name;
var productNumber = result.ProductNumber;
miniumprice = result.np_minimumsalesprice;
if (amount < miniumprice.Value) {
Xrm.Page.ui.setFormNotification('This amount is not valid. It cannot be lesser than' + amount, 'ERROR', '2');
//Xrm.Page.context.getEventArgs().preventDefault();
context.getEventArgs().preventDefault();
}
}
else {
alert(this.statusText);
}
}
};
req.send();
}
Open your form under customize mode, then tick on "Pass execution as first parameter". Then it will prevent save and will not add to your subgrid.
xrmcenter.wordpress.com/.../prevent-save-in-crm-form