自定义代码活动中的空引用异常

时间:2017-04-17 07:07:45

标签: dynamics-crm

当我在服务器上执行代码活动时,我遇到了空引用异常。

protected override void Execute(CodeActivityContext context) {          
        //IWorkflowContext executionContext = context.GetExtension<IWorkflowContext>();
        //IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
        //IOrganizationService service = serviceFactory.CreateOrganizationService(executionContext.UserId);

        //XmlDocument doc = GetEmbeddedXMLDocument();
        //XDocument xDoc = doc.ToXDocument();                       

        ////context.SetValue<bool>(IsExist, false);

        ////string ent = context.GetValue(InputEnt);
        ////string searchAtrib = context.GetValue(SearchAttrib);
        //////string condition = context.GetValue(Condition);
        ////string attribValue = context.GetValue(AttribValue);

        ////QueryByAttribute query = new QueryByAttribute(ent);
        ////query.ColumnSet = new ColumnSet(new String[] {searchAtrib});
        ////query.Attributes.Add(searchAtrib);
        ////query.Values.Add(attribValue);

        ////EntityCollection retrived = service.RetrieveMultiple(query);

        ////if (retrived.Entities.Count>0) {
        ////    context.SetValue<bool>(IsExist, true);
        ////}

        //var docData = new JObject();
        //docData = ParseDataStringToObject(context);            

        //SysColl.List<DataContainer> entityes = new SysColl.List<DataContainer>();
        //FillEntityes(xDoc, entityes);
        //entityes.OrderBy(x => x.Order).ToList<DataContainer>();

        //CreateEntityesInMemo(entityes,docData, service, context);
    }

调用函数。普通的XMLHttpRequest幕后。

var result = Process.callAction("kr_ParseInitialData",
        [{
            key: "InputEnt",
            type: Process.Type.String,
            value: json_object
        }],
        function () {
            //createAttachment(attachmentData);
            debugger
            clearFormControls();
            alert(result);
        },
        function (errInfo) {
            alert(errInfo);
        });

正如你所看到的,我评论了一切,但仍然得到了同样的例外。在Debug代码中工作正常。有任何想法吗? 此致。

2 个答案:

答案 0 :(得分:0)

这似乎是一个CRM错误。我取消注册并注册相同的DLL,代码没有任何变化。现在它按预期工作。

答案 1 :(得分:0)

您使用错误的方法来调用CallActivity。根据Process.js文档:https://processjs.codeplex.com/,您应该使用:

Process.callWorkflow("4AB26754-3F2F-4B1D-9EC7-F8932331567A", 
Xrm.Page.data.entity.getId(),
function () {
    alert("Workflow executed successfully");
},
function () {
    alert("Error executing workflow");
});

如果要使用“自定义操作”,请首先使用CRM中所需的输入/输出参数来创建自定义操作。然后在VS中创建插件项目(模板)。然后在您的Action中注册此插件(如此http://www.powerobjects.com/2016/04/11/setting-output-parameters-in-plugins-for-custom-actions/)。然后,您可以使用Process.callAction

从JS调用此操作

P.S。请注意Action默认情况下具有“Target”参数,不要忘记添加