0

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.OnSuccess

at 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.

4

1 回答 1

0

由于您应该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 设置为全局变量,而不是初始化它并传入每个函数。

于 2021-01-22T00:37:34.177 回答