Passing array to a function from workflow loop

I'm trying to run a loop a function that then loops an array passed to the function. All the individual parts seem to work, but when I run it I get a null return for everything. I can't figure out where the issue is or how to tell if the array is getting passed to the function correctly, or if I'm just trying to do something wrong

Workflow loop

Function with test param array based on what I think should be passed from the workflow loop

When running the workflow, there is nothing in the log for the function to help me troubleshoot

Hey @Peter_Kunz!

It looks like you are sending the full array body of code3's output to your createEventFunction code. It appears you just want to send the inner array of each item from code3, which would need to take the form of {{ value[i] }}

This way loop3 is looking at each of the 17 items (value in the loop block) in the top level array and sending each subset of arrays ( from the code3 return code3.data[0] => an array with 1 item, which has 8 keys) as the data to pass on.

Doesn't the loop function inherently do what you are suggesting? {{ value }} in this case is already code3.data[i]

1 Like

I think this is because loop1 doesn't return anything.


after adding a return value:


possible fixes:

  • try attaching a JS Code block after loop1 to return the loops resutls:

  • create a new function called "PostNewEvent" to create the REST request, then change the loop runner from 'Google Calendar Service' to 'Run JS Code' to call and return results:

3 Likes

oh i forgot, if you need more logging to help debug:

  • change code3 to:
    function groupByCalIdToArray(){
      console.log("NoEvent.data: ", NoEvent.data);
      const grouped = _.groupBy(NoEvent.data, 'calId');
      console.log("Grouped Data: ", grouped);
      return Object.values(grouped);
    }
    
  • change code1 to:
    console.log("Params.array: ", params.array);
    return params.array;
    
  • change the new loop1 to:
    console.log("Processing Item: ", value);
    const ret = await postNewEvent();
    console.log("New Event Result: ", ret);
    return ret;
    

now when you check the logs window you'll see everything as it's processed

I'm still having trouble passing the data to the function

I'm not sure what that function block parameter means

I'll add these and try again, thanks

Still had issues with loop3 and wasn't getting any logs. recreated loop3 like you suggest I do with loop1 in the function, and that seems to work better. Seems like maybe there is a problem with looping a multistep function?

Hi @Peter_Kunz,

Wanted to check in if you are still experiencing this issue with your workflow.

From your last screen shot, what is the intended behavior you are looking to get? Are you taking the output of code3, passing it to loop3's sub-workflow and then looking to get that data returned back to the top level workflow?

What is the purpose of loop4?

Just echoing the above - let us know if you still need assistance with this, @Peter_Kunz! I've definitely observed some flakiness with the way the loop runner interacts with multistep functions, but believe that most of those interactions should be fixed by now. That said, there's no reason not to run a script in the loop, instead!