CRM 自定义 activity 不 return 输出参数

CRM custom activity do not return output argument

我写了一个自定义 activity 如下,

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 调用此 activity。

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

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

我从未尝试过使用 web api 直接在 js 中调用自定义工作流 activity,AFAIK 并不常见。推荐的方式是把这个转成一个custom action然后在js web中调用api.

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