Keep Form from saving before the save function returns


I have a slightly nested function that will run as soon as the user presses "save".

To keep it short, the function has to call delegates (using context.executeQueryAsync) twice.

The first time calling executeQueryAsync it runs fine, the second time the forms submits the data without waiting for anything to actually finish/be loaded.

To better explain: I need to retrieve a number of ListItems using the RelatedItems field and then Loop through those and Approve those - Resulting in 2 executeAsyncQueries, one of which is in a for loop.

How can I manage this?

Dear @Troschke,
The easiest way is to replace Save button functionality, so it only sends the requests. After requests are processed, you can then manually trigger method which will close the form. More on this here - Managing form's toolbar with JS — SharePoint forms