cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Developing a recipe with recursive looping

jmcvicker
Deputy Chef II
Deputy Chef II

I am developing a recipe to look through for files and folders on Google Drive that contain a particular string in the name. As you might imagine, I need to develop a recursive loop to get into all of the nested folders. I created a parent recipe to kick off the process, which calls a recipe function (A) to look into the root level folder's files and subfolder names. Then I cloned that recipe, and called the clone (B) from the first recipe function (A). However, when I try to call recipe function A from recipe function B, I am getting an error:

Recursive invocation detected

I've tried creating even a second clone, in case the recursion was only detected if calling a recipe that was the calling recipe of the current recipe (yikes! brain spaghetti), but that did not solve the problem.

Has anyone identified a way to recursive travel down a folder structure without a pre-defined number of levels?

Jen McVicker
CSP-SM, CSP-PO, SAFe 5 SPC, ICA-AC, ICA-ATF, Automation Pro II
1 ACCEPTED SOLUTION

Unfortunately the clone-twice/delete linkage didn't work to resolve my issue. For anyone else who tries to do this in the future, I'll outline how I got around it here:

  • Create a lookup table with 5 columns: folder_name, folder_id, folder_level, logged, rename_check
  • Populate the first row of the lookup table with the root folder info: name, id, level = 1, logged = 0, rename_check = 0
  • Create a scheduled recipe to run every 5 minutes. Recipe actions:
    • Search entries in the lookup table for records where logged = 0
    • Do a repeat loop for each result found in the lookup table. In that repeat loop: 
      • Search for folders in google drive. If list size of the results > 0, batch-add the subfolders to the lookup table, setting level = level of the current folder plus one, logged = 0, rename_check = 0
      • Update the current folder record, setting logged = 1
      • If the folder name contains the string we're looking to replace, rename the folder
      • Whether or not the folder was renamed, set rename_check = 1
    • End repeat loop
  • End recipe
  • Finally, create a separate recipe to loop through all the folders in the lookup table, searching for filenames within each folder that contains the string we want to replace
Jen McVicker
CSP-SM, CSP-PO, SAFe 5 SPC, ICA-AC, ICA-ATF, Automation Pro II

View solution in original post

2 REPLIES 2

mppowe
Executive Chef I
Executive Chef I

Good morning Jen,

I believe that's a limitation of Recipe Functions to prevent infinite loops.  Is there a way you can accomplish what you want using a Repeat block instead?  I haven't used the Google Drive connector so I'm not familiar with it, but it might be an option, albeit imperfect.

Another longshot might be if the Recursive error is being thrown b/c Workato sees them as dependencies.  When you clone a recipe, the new one is "linked" to the parent recipe.  If you clone it a 2nd time, so your original is A, first clone is B, and 2nd clone is C, then delete recipe B, now C and A will be independent of one another.  You could try that too in case that link is the problem.

Unfortunately the clone-twice/delete linkage didn't work to resolve my issue. For anyone else who tries to do this in the future, I'll outline how I got around it here:

  • Create a lookup table with 5 columns: folder_name, folder_id, folder_level, logged, rename_check
  • Populate the first row of the lookup table with the root folder info: name, id, level = 1, logged = 0, rename_check = 0
  • Create a scheduled recipe to run every 5 minutes. Recipe actions:
    • Search entries in the lookup table for records where logged = 0
    • Do a repeat loop for each result found in the lookup table. In that repeat loop: 
      • Search for folders in google drive. If list size of the results > 0, batch-add the subfolders to the lookup table, setting level = level of the current folder plus one, logged = 0, rename_check = 0
      • Update the current folder record, setting logged = 1
      • If the folder name contains the string we're looking to replace, rename the folder
      • Whether or not the folder was renamed, set rename_check = 1
    • End repeat loop
  • End recipe
  • Finally, create a separate recipe to loop through all the folders in the lookup table, searching for filenames within each folder that contains the string we want to replace
Jen McVicker
CSP-SM, CSP-PO, SAFe 5 SPC, ICA-AC, ICA-ATF, Automation Pro II