我的D365实例更新到统一接口,Ribbon命令背后的JavaScript崩溃了。就我对Xrm的理解。Page需要被替换,PrimaryControl需要被添加为ribbon工作台中的Crm参数。
我这样做了,也更新了代码,但我得到了错误:
TypeError: Cannot read property 'getControl' of undefined
at Object。调用OnSuccess对象。ChangeStatusMultiple
这是代码:
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();
}
};
我错过了什么?如有任何帮助,不胜感激。
由于您希望传递context
作为函数OnSuccess: function (gridName,context)
的第二个参数,因此您必须像这样从调用位置传递Applikata.Commands.OnSuccess(gridName, formContext);
。
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, formContext);
},
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();
}
或者您也可以将formContext设置为全局变量,而不是初始化它并传入每个函数。