after taking a rollup field sum in account entity when we put the value in total amount in invoice the rollup field is not updated automatically,it updated when we refresh on the sum field.
I want the the total amount of particular customer is not greater than credit limit using javascript in web resources and rest query .
total amount field in invoice entity and credit limit field in account entity
I work but my code is not work can anyone guide me.
function limit(){
var CustomerGUID = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+CustomerGUID.slice(1,-1)+")?$select=creditlimit", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var creditlimit = result["creditlimit"];
var creditlimit_formatted = result["creditlimit@OData.Community.Display.V1.FormattedValue"];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?$select=name,pre_sum", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var name = results.value[i]["name"];
var pre_sum = results.value[i]["pre_sum"];
var pre_sum_formatted = results.value[i]["pre_sum@OData.Community.Display.V1.FormattedValue"];
if(CustomerGUID ==name)
{
if(creditlimit>pre_sum)
{
alert("not entered");
}
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}