The following JS function is used to refresh Rollup field through webapi fom javascript
function calcRollupField(serverURL,strTargetEntitySetName, strTargetRecordId, strTargetFieldName)
{
strTargetRecordId = strTargetRecordId.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v9.0/" +
"CalculateRollupField(Target=@p1,FieldName=@p2)?" +
"@p1={'@odata.id':'" + strTargetEntitySetName + "(" + strTargetRecordId + ")'}&" +
"@p2='" + strTargetFieldName + "'", false);
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.onreadystatechange = function () {
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
var results = JSON.parse(this.response);
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify({}));
}
function calcRollupField(serverURL,strTargetEntitySetName, strTargetRecordId, strTargetFieldName)
{
strTargetRecordId = strTargetRecordId.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v9.0/" +
"CalculateRollupField(Target=@p1,FieldName=@p2)?" +
"@p1={'@odata.id':'" + strTargetEntitySetName + "(" + strTargetRecordId + ")'}&" +
"@p2='" + strTargetFieldName + "'", false);
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.onreadystatechange = function () {
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
var results = JSON.parse(this.response);
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify({}));
}
No comments:
Post a Comment