This topic was automatically generated from Slack. You can find the original thread here.
Frank : Hello - can someone point me into the right direction on how I can iterate through an array of results?
For example, I run a query on Airtable and get a response with [2] records. I now want the next step in my workflow to iterate through both those results. How do I do this?
Dylan Sather (Pipedream) : Hi , to do this right now, youâll need to write just a bit of Node.js code. Hereâs a good reference on loops.
Within the step where you want to iterate, youâll need to modify the code of that step - just click into the step and start typing. At the top of the step, youâll need to iterate over the array of results (steps.airtable_get_tasksOutstanding.$return_value.records), running the original code of the step for each element of the array:
for (const record of steps.airtable_get_tasksOutstanding.$return_value.records) {
// original code here
}
It looks like each record is an object, so you can reference record.fields to grab the fields for each item in the array, for example.
@pierce any development on Pipedream iterator? Today I checked Helper Functions but havenât found an iterator helper.
I tested the suggested code like:
for (const record of steps.advanced_search.$return_value.records) {
var tempArray = steps.advanced_search.$return_value[record].entities;
...
}
but I got back error:
TypeError, steps.advanced_search.$return_value.records is not iterable
despite it is an array of 100 objects.
Pls note
steps.advanced_search.$return_value
doesnât have a visible ârecordsâ property ( it might be a hidden system property though )
If I remove ârecordsâ property from code like:
for (const record of steps.advanced_search.$return_value) {
var tempArray = steps.advanced_search.$return_value[record].entities;
...
}
I got error message of:
TypeError, Cannot read property âentitiesâ of undefined
I donât want to bump or OFF the OP, but my issue is just the same as OP:
âHow do I iterate through an array of results from a step?â
Thatâs correct, unfortunately we donât have a built in array iterator at this time, and that Github Issue you linked to is the best place to subscribe to future updates.
Improving control flow is a top item on our roadmap and we know this would be super impactful to making workflows even easier to work with and improve productivity.
That said, the approach youâre taking now is the correct one.
The only issue is that youâll need to tweak the pathing to your step exports a bit.
Can you share a screenshot of the advanced_search exports result? That would help us understand the structure of your data and help guide you on how to iterate it.
// To use previous step data, pass the `steps` object to the run() function
export default defineComponent({
async run({ steps, $ }) {
for(const record of steps.advanced_search.$return_value) {
console.log(record.full_text);
}
},
})
Hello. Whatâs the latest on this? How does Pipedream suggest that we iterate through a stepâs array to do X, such as add rows of that data to another tool? Thanks.
Iâm considering using Pipedream instead of Zapier for a project, and this lack of loops and conditional logic is a considerable showstopper.
Iâve seen the discussion in the Git issue where itâs suggested to use additional workflows, but this exponentially increases the credit consumption and totally undermines the pricing model of it being time based as opposed to task based.
Sure, can code loops in node, but then whatâs the point of the whole framework if subsequent calls based upon the loop data have to be in code instead of the UI. I may as well just code the whole thing.
What am I missing here?