Krivitskiy Grigoriy
Krivitskiy Grigoriy

Reputation: 406

Null reference exception in custom code activity

I run into null reference exception when I execute code activity on server.

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

calling function. Ordinary XMLHttpRequest behind the scene.

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

As you can see, I comment everything, but still get the same exception. In Debug code works fine. Any ideas? Sincerely.

Upvotes: 1

Views: 452

Answers (2)

Denys Demchenko
Denys Demchenko

Reputation: 218

You are using wrong method to call CallActivity. According to Process.js Documentation: https://processjs.codeplex.com/ you should use:

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

If you want to use Custom Action, then first create custom action with Input/Output paramerters you want in CRM. Then create Plugin Project (Template) in VS. Then register this plugin at your Action (like this http://www.powerobjects.com/2016/04/11/setting-output-parameters-in-plugins-for-custom-actions/). Then you can call this action from JS using Process.callAction

P.S. Pay attention that Action have "Target" paramenter by the default, don`t forget to add it

Upvotes: 0

Krivitskiy Grigoriy
Krivitskiy Grigoriy

Reputation: 406

It's seems it was a CRM bug. I unreg and reg the same dll, nothing change in code. Now it works as intended.

Upvotes: 1

Related Questions