Hello,
I written one JS Code this code is working fine Form level page is but, in User Interface am getting Error.
//==============================================================
//In Order Entity Total DD Instalment records Count is automayically.
//=============================================================
function RefreshTotalInstallmentsField(executionContext) {
try {
var formContext = executionContext.getFormContext();
var countOnForm = formContext.getAttribute("new_totalinstalment").getValue();
var OrderId = formContext.data.entity.getId().replace('{', '').replace('}', '');
Xrm.WebApi.online.retrieveMultipleRecords("new_directdebitinstalment", "?$select=new_id&$filter=_new_directdebitrenewalid_value eq '" + OrderId + "'").then(
function success(results) {
if (results.entities.length != countOnForm) {
CalculateTotalInstallmentsRollupField(executionContext);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
} catch (e) {
console.log(e.message);
}
}
function CalculateTotalInstallmentsRollupField(executionContext) {
try {
var formContext = executionContext.getFormContext();
var OrderId = formContext.data.entity.getId().replace('{', '').replace('}', '')
var parameters = {};
var target = {};
target.salesorderid = OrderId; //Delete if creating new record
target["@odata.type"] = "Microsoft.Dynamics.CRM.salesorder";
parameters.Target = target;
parameters.FieldName = "new_totalinstalment";
var calculateRollupFieldRequest = {
Target: parameters.Target,
FieldName: parameters.FieldName,
getMetadata: function () {
return {
boundParameter: null,
parameterTypes:
{
"Target": {
"typeName": "mscrm.crmbaseentity",
"structuralProperty": 5
},
"FieldName": {
"typeName": "Edm.String",
"structuralProperty": 1
}
},
operationType: 1,
operationName: "CalculateRollupField"
};
}
};
Xrm.WebApi.online.execute(calculateRollupFieldRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
formContext.data.refresh();
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
} catch (e) {
console.log(e.message);
}
}