My D365 instance updated to Unified Interface and the JavaScript behind Ribbon Commands broke. As I understand Xrm.Page needs to be replaced and PrimaryControl to be added as a Crm Parameter in ribbon workbench.
I did that, updated the code as well but I get the error:
TypeError: Cannot read property 'getControl' of undefined
at Object.OnSuccessat Object.ChangeStatusMultiple
This is the code:
Applikata.Commands =
{
ChangeStatus: function (id, entityName, status, state, successCallback,context) {
var formContext = context;
var entity = {};
var arrStatus = status.SourceControlId.split("|");
var _status = (state == 0) ? 100000000 : 100000002;
// status arraives in following form
// ac_grade | NoRelationship | Form | ac.ac_grade.Button17.Button
if (arrStatus.length == 4)
_status = arrStatus[arrStatus.length - 1].split(".")[2];
entity.statuscode = { Value: _status };
entity.statecode = { Value: state };
//console.log(status);
// ac_grade|OneToMany|SubGridAssociated|ac.ac_grade.100000008.GridButton
//console.log("ChangeStatus:" + id + " entityName:" + entityName + " status:" + status + " state:" + state);
//console.log("SDK.REST:" + SDK.REST);
SDK.REST.updateRecord(
id,
entity,
entityName,
successCallback,
function (error) {
alert(error.message);
}
);
},
ChangeStatusMultiple: function (selectedIds, entityName, status, state, gridName, context) {
var formContext = context;
selectedIds.forEach(
function (id) {
Applikata.Commands.ChangeStatus(id, entityName, status, state, function () {});
}
);
Applikata.Commands.OnSuccess(gridName);
},
OnSuccess: function (gridName,context) {
var formContext = context;
console.log('Control ' + gridName);
console.log('Name of grid' + formContext.getControl(gridName,primaryControl).getName());
// Xrm.Page.getControl(gridName).getName().refresh();
formContext.getControl(gridName,primaryControl).refresh();
}
};
what am I missing? Any help would be appreciated.
Since you are expected to pass
context
as second parameter for the functionOnSuccess: function (gridName,context)
, you have to pass like thisApplikata.Commands.OnSuccess(gridName, formContext);
from calling place.Or you can set the formContext as global variable as well, instead of initializing it and passing in each function.