Monday, 15 April 2019

Web API request to refresh Rollup field Dynamic 365 through JavaScript

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({}));
}

No comments:

Post a Comment

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...