简体   繁体   English

Microsoft Dynamics CRM 365通过JavaScript异步调用操作

[英]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.

相关问题 Dynamics Crm 365 webapi - 通过 javascript 发布网络资源 - Dynamics Crm 365 webapi - publish webresource via javascript 使用Javascript在Microsoft Dynamics CRM 2016中运行操作 - Run Action in Microsoft Dynamics CRM 2016 using Javascript 在 Dynamics CRM 中使用 JavaScript 调用全局自定义操作 - Calling global custom action using JavaScript in Dynamics CRM 如何在Microsoft dynamics crm 365中通过javascript获取查找字段的值 - How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365 Microsoft Dynamics 365 统一接口 - JavaScript - Microsoft Dynamics 365 Unified Interface - JavaScript Microsoft Dynamics CRM 2013中的Javascript兼容性错误 - Javascript compatability errors with Microsoft Dynamics CRM 2013 使用javaScript访问Dynamics CRM / 365表单中的其他实体属性 - Accessing Other Entities Attributes in Dynamics CRM/365 Forms with javaScript 动态365 crm托管解决方案不覆盖Javascript Web资源 - dynamics 365 crm managed solution not overriding Javascript webresource 在Dynamics 365 CRM App中导航 - Navigating in the dynamics 365 CRM App 如何将 javascript 添加到 Microsoft Dynamics 365 中的 web 表单 - how to add javascript to a web form in Microsoft Dynamics 365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM