gpt4 book ai didi

javascript - 如何从 Javascript Microsoft Dynamics 调用操作

转载 作者:行者123 更新时间:2023-11-30 19:38:33 25 4
gpt4 key购买 nike

我需要从 Javascript 调用操作流程。我的操作接受 2 个输入参数和 1 个输出参数。下面是我的Action截图

enter image description here我的表单中有一个 textField,在它的 onChange 事件上我调用了这个 CallAction 方法。下面是 JavaScript

function CallAction() {

var actionName = "taqi_getPrice";
var actionParameters = {
"base": "USD",
"TotalPrice": "200"
};
var actionResponse = activateCustomAction(actionName, actionParameters);
}
function activateCustomAction(actionName, actionParams) {

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/taqi_getPrice", false);
req.setRequestHeader("OData-MaxVersion", "4.0");

req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
alert('Success');
} else {
alert('fail');
//Xrm.Utility.alertDialog(this.statusText);
console.log(this);
}
}
};
req.send(JSON.stringify(actionParams));
}

运行此脚本时,我在 chrome 控制台中收到以下错误

POST https://techgulf.crm4.dynamics.com/api/data/v9.0/taqi_getPrice 404

有时它也说

Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers

最佳答案

好吧,我创建了与您在屏幕截图中提到的完全相同的操作,除了我使用的实体是帐户。我使用下面的代码来触发 Action,它确实对我有用,没有任何问题,并按预期返回了值。

enter image description here

可能用于测试,您可以提供静态 Guid 并查看如何获得结果。

var parameters = {};
parameters.base = "123";
parameters.TotalPrice = "222";
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts(DC86C293-CA4F-E911-A82F-000D3A385A1C)/Microsoft.Dynamics.CRM.crmp_TestAction2", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(parameters));

关于javascript - 如何从 Javascript Microsoft Dynamics 调用操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55678927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com