如何在Javacript中调用MS CRM操作

问题描述 投票:-1回答:1

我已经尝试过下面的链接以在JavaScript中调用Action,但是它没有在下面的代码行中获取数据:

var data = JSON.parse(this.response);
alert(data);//Error data undefined

https://nishantrana.me/2017/05/27/sample-code-to-call-action-using-web-api-in-crm/

javascript dynamics-crm action dynamics-crm-webapi
1个回答
0
投票

如果您在线,您可以执行类似的操作(这是“未绑定操作”的示例:]

var executeSurveyMonkeyAction = function (surveyMonkeyParameterSetId) {
var reference = {};
reference.entityType  = "ade_surveymonkeydialogsparameterset";
reference.id = surveyMonkeyParameterSetId;

return new Promise(function (resolve, reject) {
    var executeActionRequest = {
        SurveyMonkeyDialogParameter: reference,
        getMetadata: function () {
            return {
                boundParameter: null,
                parameterTypes: {
                    "SurveyMonkeyDialogParameter": {
                        typeName: "mscrm.ade_surveymonkeydialogsparameterset",
                        structuralProperty: 5
                    }
                },
                operationType: 0,
                operationName: "ade_ProjectSurveyMonkey"
            };
        }
    };

    parent.Xrm.WebApi.online.execute(executeActionRequest).then(
        function (response) {
            if (response.ok) {
                if (response.status == 204) {
                    return new Promise((function (resolve) {
                        resolve({});
                    }));
                }
                return response.json();
            } else {
                throw new Error("Unknown error occured in ISV code.");
            }
        },
        function (error) {
            console.log(error.message);
            reject(error);
        }
    ).then(
        function (response) {
            if (!!response) {
                resolve(response);
            } else {
                console.log("no response");
            }

        },
        function (error) {
            console.log(error.message);
        });
});
}

这里是绑定动作请求的示例:

 var executeActionRequest = {
        entity: {
            entityType: entityName,
            id: recordId
        },
        getMetadata: function () {
            return {
                boundParameter: "entity",
                parameterTypes: {
                    "entity": {
                        typeName: "mscrm." + entityName,
                        structuralProperty: 5
                    }
                },
                operationType: 0, // This is an action. Use '1' for functions and '2' for CRUD
                operationName: actionName
            };
        }
    };
© www.soinside.com 2019 - 2024. All rights reserved.