Views:

Question:
How do I loop through a keyword field or variable in Workflow Manager?

Answer: 
At first, please be aware of a known limitation when using loops; after one task (e.g. condition "loop condition") has ben executed 50 times without human interaction the loop detection will be triggered and the workflow will be unpublished! Here's how to avoid that (On-Premise only).

Now that you know, you can set up the "keyword loop" using the following steps: 

  1. Create empty tasks, name and connect them as in the screenshot
    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
    set counter
  4. In the condition, you check if the loop has to run again or is at its end
    loop condition
  5. Inside the loop, you get the text of the line you are processing at the moment and increase the loop counter
    loop
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?