简体   繁体   中英

How to call MS CRM action in JavaScript

I have tried the below link to call Action in JavaScript, but its not getting the data in the below line of code:

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/

If youre Online you can do something like (This is an example for Unbound Action):

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);
        });
});
}

Here is example for Bound Action Request:

 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
            };
        }
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM