How can I read nintext variable from C# code?

  • 29 December 2015
  • 9 replies
  • 13 views

Badge +2

Dears,

I want to know if I can read nintext variable from C# code?


9 replies

Userlevel 7
Badge +17

Mohammad, I'm not sure the context from which you would like to read the variable. There is a Workflow SDK The Nintex Workflow 2013 SDK is (initially) released!​ You can create custom actions within workflows using c#. Please provide more information on what you are trying to do so we can help.

Badge +2

I declared variable in nintex workflow, I want to get the value of the variable in my code C#.

Userlevel 7
Badge +17

Sorry, I still have no context here. I don't see how a workflow will communicate with your code. Is your code a solution in SharePoint or is it hosted elsewhere? Does the code run from a dll in the server farm? How will the code get in context with the workflow since the workflow is stateless with the database and running in either the Application Pool or through the OWStimer through the SharePoint Foundation Workflow Timer? So the workflow can be in multiple places depending on several variables. Do you need to get the variable value while in flight or after it is complete?

The most simplest way you can do this is to have the workflow variable stored into a SharePoint list using the Set Field, Update Item, Update Multiple Items, or Create Item action. Then the value of the workflow variable will have a state and you can get that value using the server API or CSOM api to fetch the value, or even use PowerShell as you can uase c# code in PowerShell.

Please provide a little more guidance and I'm sure we can find a solution for you.

Userlevel 7
Badge +17

Let us know if you have any further questions, or mark an answer. Thanks!

Badge +11

I agree with Andrew here. I would create a Nintex variable and set that variable in a SharePoint column. But I would use the SharePoint API C# code to access the value.

Badge +2

I believe I have a similar question. I am creating multiple custom actions/activities and need to access a variable from the first action in an action that would be placed downstream in the workflow. I set the value of the variable in my c# code, for the first custom action. How do I access this value from the second custom action?

In the 2007 SDK, it appears there used to be an object called "CurrentWorkflowVariableValues". This does not exist in the 2013 SDK.

NWContext ctx = new NWContext(

                this.__Context,

                new Guid(this.__ListId),

                this.__ListItem,

                this.WorkflowInstanceId,

                CurrentWorkflowVariableValues,

                this);

Based on the name, it would seem like this would have provided the necessary information, however, I do not know as it isn't in the 2013 SDK. It would be great if anyone has an idea on how to access a variable that was set in the Activity class of a previous custom action.

Thanks,

Michael

Userlevel 7
Badge +17

In your second custom action, could you create a value that needs to be configured, but use the variable within the configuration? There are many benefits to using the variable as a configuration instead of hardcoding the reference.

Badge +2

Hey Andrew,

Thanks for the response. I'm not certain I understand. Probably my inexperience with Nintex, but let me clarify my issue a bit to see if your answer is still the same. happy.png

In my first custom action, I make a REST call in my execute code of my activity. I need to pass this value through to the next action to use as part of its functionality without the end user (person setting up the workflow) ever having to specify a variable for this.

Thank you again for any suggestions!

Michael

Userlevel 7
Badge +17

That may be difficult within the API. The result of the first action needs to be saved in something that can keep the state of the result. The action itself at runtime is stateless. Variables are what keep a result within the scope of the current workflow.

My first thought was to have a result output of the action and have the user drop in a variable that fits the type. Then in the subsequent action the user drops the same variable into an input config. Similar to how for each loops work with a collection variable, where you must set a current item variable to be used within the loop.

If you can't do this, you could use a list within the site to save to and query from during the process. Have it either configured or hard coded, but that would require extra setup to use the actions.

I don't know of a way to hard code a workflow variable within the api to use among actions.

Is there any reason you do not combine the activities of the two actions if one requires the output of the other?

Reply