Question:
How do I loop through a keyword field or variable in Workflow Manager?
Answer:
Please be aware of a known limitation when using loops; after one task (e.g., condition "loop condition") has been executed 50 times without human interaction, the loop detection will be triggered, and the workflow will be unpublished.
To avoid this, please refer to KBA-35837 (On-Premise only). Once addressed, please refer to the following guide to loop through a keyword field or variable;
- Create empty tasks, name and connect them. See our example below of how this could be configured.
- Create the following three variables: keywordCount (Numeric), i (Numeric), lineContent (Text)
- Set the loop counter to '0' and get the count of lines in the keyword field.
Workflow global variable = keywordCount = Arithmetic expression = DW_KEYWORD.Count()
Workflow global variable = i =Fixed entry = 0
- In this condition, you check if the loop has to run again or is at its end.
GV_i >= GV_keywordCount
- Inside the loop, you get the text of the line you are processing at the moment and increase the loop counter.
Workflow global variable = line = Arithmetic expression = DW_KEYWORD[GV_i]
Workflow global variable = i = Arithmetic expression = GV_i + 1
KBA is applicable to both Cloud and On-premise Organizations
Beware that using the Count() method works for getting the length of empty keyword fields that are index fields (the example shown uses DW_KEYWORD, which is obviously an index field), but fails when used on empty keyword fields that are global variables with an ArgumentNullException in the workflow designer and with "Fehler in der Systemaktivität: Der Wert darf nicht null sein. Parametername: source" in the Workflow history.
I hope this is helpful to other folks using cloud instances.