How to get openURL in Function called in Custom Action to "wait" until all selected records have updated

How to get openURL in Function called in Custom Action to "wait" until all selected records have updated

My goal is to set the invoice number of selected billing records in a view and then open an Invoice form that loads its field values based upon the values of that selected group of billing records. 

In the code below the Function SetPayCode sets the InvoiceNumber field for each billing record selected from the Session Form which has a current InvoiceNumber value of "0 (Not Yet Billed)... to the value of the field named Code that exists in a InvoiceNumberList Form record with the field named FilterAid that has the value "new".  AFTER the function completes all these record updates, ONLY THEN  do I want to initiate the openURL of the form Invoice which loads with the values aggregated from those Session records which were just updated.  

I'm not sure this can be done in a Custom Action, and have been studying This Answer by Latha and Ruben as an alternative route, but have not been able to understand it completely enough to experiment with it.  Any help will be appreciated.

  1. void SetPayCode(Session NotBilled)
  2. {
  3.     for each NotBilled in Session
  4.     {
  5.         if (NotBilled.InvoiceNumber  ==  "0 (Not Yet Billed)")
  6.         {
  7.             rec  =  InvoiceNumberList  [FilterAid == "new"];
  8.             NotBilled.InvoiceNumber = rec.Code;
  9.         }
  10.     }
  11.     openUrl("#Form:Invoice", "Popup window", "height=500,width=400");
  12. }