Hi,
I want to create a global variable on a list. Every time a new item is created and a condition is met I want to increase that number by 1.
How can I create global variables and how can I update them?
I tried workflow constants, but you cannot update them.
Thanks in advance
Karin
Solved! Go to Solution.
There is no concept of global variable in a workflow. All variables are reset in a new instance of the workflow. You could create a column in your list of number type. When the new item is created and your condition is met, read the previous value of this variable using max(ID)-1 which will give you the value of this column 1 previous to current item. Once you have the value, increment it by 1 and save it in the column. Hope that helps.
Said that, why cant you use ID field which is auto-generated and always increments by 1 automatically.
Thank you. Than I will rather make a second list, where I will store those values. Like I did before, I just thought it would be great if something like a global variable would exist.
I cannot use the ID, because this is a tracking number but I have several tracking numbers for different types in the same list. So using the ID does not work.
You could use a SQL Table?? Not much difference than using a list though..
Or, use a Constant and update and read it using Execute SQL Action.
Update
Update {databasename}.dbo.WorkflowConstants
Set Value="{Insert Value Here}"
Where Title="{Constant Name}" and SiteId="{GUID}"
Read
select [Value] from {databasename}.dbo.WorkflowConstants
Where Title="{Constant Name}" and SiteId="{GUID}"
Dan - I always assumed that writing to the Nintex DB tables was not supported. Is that fully supported - to execute SQL Update commands against the WorkflowConstants table?
Karin Hobelsberger - do you expect that multiple users might ever update this variable at the same time? If so, then I would definitely use a SQL table instead of a SharePoint list, as SQL will allow you to manage concurrency and prevent userA from overwriting userB. However, you will need to create a stored procedure with lock hints and explicit SQL transactions. Also, when you increment your counter, I assume you need the new value to be returned to the workflow, correct?
About 5 - 6 years ago, I did some presentations around InfoPath and one section of that presentation was how to implement a global counter using SQL. I dug up the presentation including the stored procedure that I created. I believe the code below is 100% bulletproof to ensure that if multiple users try to update the counter at the same time, they each get a unique value and concurrency is always maintained. In this example, we had a unique counter for each form, and the SQL table had two columns: FormName (VARCHAR) and FormCounter (INT). But you could tweak the column names as appropriate for your use case. I have a whole slide presentation on how to implement this solution that could be easily adapted to a Nintex Workflow. Let me know if you need more details.
-Tom Castiglia