How to make sure my workflow steps complete only when records are processed?

Hi All,

I have a few JavaScript queries that trigger a rest api, when I run this all manually it works all fine but when I run it as a full workflow it sometimes starts my second javascript and restapi query before the other one is finished, how can I fix this? I already tried with async but that does not help

So it should first finish all records in checkDelete and when done it should continue with PostContacLoop

Hey @Sander! For your current setup a simple change to the checkDelete code block should ensure it runs completely before moving to postContactLoop. Can you add an await before deleteEmails() on line 11?

Without that, the JS code block 'returns' and moves on before the inner loop is done.

As an aside, I see that you are triggering unconnected code blocks (postDelete, postContact). While this is presumably working for you, we have seen that pattern break down in a few circumstances. We recommend leveraging functions in this case. And the calling syntax is easier as well (no need for additionalScope)!

Screenshot of that syntax as well here for you:

Let me know if you have any other questions!