首页 > 解决方案 > CRM 自定义活动不返回输出参数

问题描述

我写了一个自定义活动如下,

namespace Tu.Crm.Packages.WorkFlows
{
    public sealed class VersionFinder : CodeActivity
    {
        [Output("VersionDate")]
        public OutArgument<string> VersionDate { get; set; }

        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
           
            try
            {
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                VersionDate.Set(executionContext, "1#22/01/2019");
                
            }
            catch (FaultException<OrganizationServiceFault> e)
            {
                // Handle the exception.
                throw new InvalidPluginExecutionException("Some error occurred/Proxy service unreachable" + e.StackTrace);
            }
        }
    }
}

我正在尝试从 JavaScript 调用此活动。

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_versionfinderc2dcf0b12782eb11814500155de400c4", 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 === 204) {
            Xrm.Utility.alertDialog(this.ResponseXML);
        } else {
            Xrm.Utility.alertDialog(this.ResponseXML);
        }
    }
};
req.send();

但是,它不返回任何数据。有什么问题?

标签: javascriptdynamics-crmcustom-actiondynamics-crm-webapicustom-activity

解决方案


我从来没有尝试过使用 web api 直接在 js 中调用自定义工作流活动,而且通常不做 AFAIK。推荐的方法是将其转换为自定义操作并在 js web api 中调用它。

如果要保留此 CWA,请在 UI 工作流中使用它并从 js web api 执行 WF。您也可以在自定义操作中使用 CWA。


推荐阅读