Views:

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; 

  1. Create empty tasks, name and connect them. See our example below of how this could be configured. 
     

    Written Representation of Workflow Connect


    overview
     
  2. Create the following three variables: keywordCount (Numeric), i (Numeric), lineContent (Text)
    variables

     
  3. 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

    set counter
     
  4. In this condition, you check if the loop has to run again or is at its end.

    GV_i >= GV_keywordCount

    loop condition

     
  5. 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


    loop

KBA is applicable to both Cloud and On-premise Organizations

Comments (4)
  • Careful with keyord fields that may be emtpy! (Version 7.3)

    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 know this is a late reply, but if checking the .Count() method or .Length property on a keyword global workflow variable you can check if it is null first with GV_KeyWord = null.  Then if it's not null you can check the length.
  • I was able to make this work in a cloud instance by storing the loop index (i in this article) as an index field (let's call it i_stored) and only looping in the workflow until i = i_stored + 40 or i = myKeyword.Count(), where 40 is some number that is less than the maximum number of loops for our instance. The workflow gets triggered when i_stored is updated and i_stored >= 0 in order to continue looping, so the way to trigger it initially is by setting i_stored as zero. I also had to add a 1-minute delay to the end of the workflow to keep it from being unpublished for starting too many workflow instances at once. This will be a bit slow for very large keywords fields, but it gets the job done.

    I hope this is helpful to other folks using cloud instances.
  • Does this array feature/function only work with Keyword Index fields? I'm trying to use this with a Keyword Global Variable, and I cannot get the Validate error to disappear,  I tried changing to an index field, and still cannot get the validate error to clear. Is there a known problem with the Docuware Cloud?