[英]Microsoft Dynamics CRM 365 calling an action via JavaScript asynchronously
Is there a way to call an action via javascript without the use of third party scripts? 有没有办法在不使用第三方脚本的情况下通过javascript调用动作?
I found this https://github.com/PaulNieuwelaar/processjs 我发现了这个https://github.com/PaulNieuwelaar/processjs
However, I cannot use third party libraries. 但是,我不能使用第三方库。
UPDATE: 更新:
Here is some sample code that demonstrates an asynchronous call to an action via JavaScript. 这是一些示例代码,演示了如何通过JavaScript异步调用某个动作。 A important point to remember is to make the last parameter of the open method of the request to true .
要记住的重要一点是将请求的open方法的最后一个参数设为true 。
req.open(consts.method.post, oDataEndPoint, true);
// plugin // 插入
public class RunAsync : CodeActivity
{
[Input("input")]
public InArgument<string> Input { get; set; }
[Output("output")]
public OutArgument<string> Output { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
try
{
Thread.Sleep(20000);
Output.Set(executionContext, $"Result:{Input.Get(executionContext)}");
}
catch (Exception e)
{
throw new InvalidPluginExecutionException(e.Message);
}
}
}
// javascript // JavaScript
function callAction(actionName, actionParams, callback) {
var result = null;
var oDataEndPoint = encodeURI(window.Xrm.Page.context.getClientUrl() + consts.queryStandard + actionName);
var req = new XMLHttpRequest();
req.open(consts.method.post, oDataEndPoint, true);
req.setRequestHeader(consts.odataHeader.accept, consts.odataHeader.applicationJson);
req.setRequestHeader(consts.odataHeader.contentType, consts.odataHeader.applicationJson + ";" + consts.odataHeader.charset_utf8);
req.setRequestHeader(consts.odataHeader.odataMaxVersion, consts.odataHeader.version);
req.setRequestHeader(consts.odataHeader.odataVersion, consts.odataHeader.version);
req.onreadystatechange = function () {
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
if (callback) {
result = JSON.parse(this.response);
callback(result);
}
} else {
console.log(JSON.parse(this.response).error);
}
}
};
req.send(JSON.stringify(actionParams));
}
function onLoad() {
console.log('call action...');
var actionParams = {
Input: 'test1234'
};
callAction('TestAsyncAction',actionParams, function(data){
console.log('action callback triggered...');
console.log(JSON.stringify(data));
});
console.log('action called...');
}
// Action //动作
You can use webapi to execute custom Action . 您可以使用webapi执行自定义Action 。 This is wrapped in
XMLHttpRequest
& can be called asynchronous. 它包装在
XMLHttpRequest
,可以称为异步的。
/api/data/v8.2/Action_Name
For asynchronous run: 对于异步运行:
req.open(....., true);
The same using soap call (not recommended). 使用肥皂调用也一样 (不推荐)。
Processjs
uses Organization.svc/web
which is going to be deprecated. Processjs
使用将不推荐使用的Organization.svc/web
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.