Skip to main content

I have two custom actions (eventually I'll have a third). In my first action, I collect values necessary to call a REST API. The API performs its duties and returns an ID. In my second custom action, I need to use this ID to perform a status check on the job that was created with the first action. How do I pass this value through the workflow context from action 1 and access it from action 2 (and 3, when I get that far)?

Thanks in advance for any help!

Anyone have any idea how to access a variable from a previous workflow activity, from another custom activity in C#?


I'm not sure the nomenclature of what you mean by a user defined action. I am creating a custom action & activity to make a call to a REST API. That REST call will return an ID in the response payload. I need to pass this value through the workflow to be accessed by the second action downstream.

So, in my actionAdapter.cs code, I define a variable:

c.Parameters[7] = new ActivityParameter();

c.Parameters[7].Name = Parameter_ObjectIdOutput;

c.Parameters[7].Variable = new NWWorkflowVariable();

Then, in the execute method of my Activity.cs, I run my code to access our service using the configuration info provided in the action (when placed in the workflow). This returns me the response payload, with my object ID. I push this to my action variable "ObjectIdOutput".

this.ObjectIdOutput = objectId; //where objectId is the value returned from my service.

ctx.Variables.Add("ObjectIdOutput", ctx.AddContextDataToString(ObjectIdOutput, true)); //this was added to try the next step below

In the second custom action/activity, I need to be able to grab this object ID so that I can run a status check, via the REST API for our service. I have not been able to find any example of grabbing this value. I've tried several things, including trying to grab it from:

string oID = ctx.Variables["ObjectIdOutput"].ToString();

This obviously isn't right as I get an error when I place both in a workflow and execute it. The first action runs successfully, but the second fails when it cannot access that variable.


Reply