javascript - 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();
但是,它不返回任何数据。有什么问题?
解决方案
我从来没有尝试过使用 web api 直接在 js 中调用自定义工作流活动,而且通常不做 AFAIK。推荐的方法是将其转换为自定义操作并在 js web api 中调用它。
如果要保留此 CWA,请在 UI 工作流中使用它并从 js web api 执行 WF。您也可以在自定义操作中使用 CWA。
推荐阅读
- unity3d - Unity 询问 NDK 版本不再可用
- regex - Bigquery 中带有字符串值的 REGEXP_EXTRACT
- google-cloud-platform - Google Cloud:磁盘标签未从实例模板或图像继承
- .htaccess - CSS & JS 文件未加载到我的 cakphp 应用程序中
- python - ValueError: n_components=256 必须介于 0 和 min(n_samples, n_features)=11 之间,且 svd_solver='full'
- linux - 捕获 v4l:没有捕获设备 - 但视频捕获多平面?
- autodesk-forge - Autodesk GuiViewer3D initialize gives an error
- python - Python在查询SQLAlchemy关联表时返回AttributeError('function'对象没有属性'c')
- php - PHP HTTP 重定向在 Azure 应用服务上不起作用
- python - 为什么我在无限循环中休眠的 python 脚本停止运行?