This discussion is archived
6 Replies Latest reply: Apr 9, 2013 11:55 AM by Joe Upshaw RSS

How to Wait for trigger('apexrefresh') to Complete Before Proceeding

Joe Upshaw Journeyer
Currently Being Moderated
All,

I am sure this is a silly problem but, I've been stuck on this for a while. I need to refresh a report region on demand and then, examine the content to determine what should be done next. The problem is that the call to trigger('apexrefresh') appears to be asynchronous and I need to find a way to make it block until the refresh has completed. In other words, the code following the refresh just continues on without waiting.

For example:
function popupProfileCopyDialog(targetProductProfileID)
{     var mismatchCnt     = 0;

     setTargetProductProfileID( targetProductProfileID );
     $('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').trigger('apexrefresh');
     
     mismatchCnt = $('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').find( 'span.profilePropertyMismatch').length;
     
     alert( mismatchCnt );     
}
In the case of the above code, if a span occurs with a class of profilePropertyMismatch, I'd want to incement this count. However, the count is being performed immediately, i.e. not after the refresh. That is, run it the first time, get 0 for the mismatchCnt (because the region is still empty). Run it again, get 1 (one row with a span that has this class). Change to another row, refresh on one with 0 profilePropertyMismatch spans, still get 1 (from the previous refresh). Run again, get 0. etc.

How can I make the code wait for the call to $('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').trigger('apexrefresh'); to complete before proceeding to the next line?

Thanks,

-Joe
  • 1. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    jariola Guru
    Currently Being Moderated
    Hi,

    Have you think use dynamic action that fires after region refresh?


    Regards,
    Jari
    -----
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai
  • 2. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    Nicolette Expert
    Currently Being Moderated
    Joe

    On the refresh of a region 2 events are fired the before refresh and the after refresh
    mismatchCnt = $('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').find( 'span.profilePropertyMismatch').length;
    Must be run by a trigger on the after refresh event.

    Easiest would be using a dynamic action.

    Nicolette
  • 3. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    Joe Upshaw Journeyer
    Currently Being Moderated
    Yes, Jari, I am aware of the After Refresh event but, that really won't work in this case. I paired down the function to just illustrate the problem with the least extraneous detail.

    What is really happening is that the function is deciding whether or not to popup a dialog based on whether there are any mismatches. At that point, the user may click Apply (to overlay a target form a source), Skip (just skip this one and go on to the next one) or Abort (Stop the process entirely). The method must capture which of these actions were taken and then pass this back to the calling function.

    And there's more...there are really several of these regions that I need to refresh and then sum up all of these counts.

    I tell you all of this to say that it all must occur within one logical unit of work. So, what I really need is something like to the following pseudo-code:
    function popupProfileCopyDialog(targetProductProfileID)
    {     var mismatchCnt     = 0;
     
         setTargetProductProfileID( targetProductProfileID );
         
         var completed = waitForCompletetion($('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').trigger('apexrefresh'));
         
         mismatchCnt = $('section#PROFILE_TERM_PROPERTY_INSTANCES_RR').find( 'span.profilePropertyMismatch').length;
         
         alert( mismatchCnt );     
    }
    Any ideas?

    -Joe
  • 4. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    Joe Upshaw Journeyer
    Currently Being Moderated
    Hi Nicolette. Please see my response to Jari. Using the built-in After Refresh method really won't work in this, particular case. I am aware of, and use, the Before Refresh and After Refresh events regularly.

    Thanks,

    -Joe
  • 5. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    VC Guru
    Currently Being Moderated
    Joe Upshaw wrote:
    Hi Nicolette. Please see my response to Jari. Using the built-in After Refresh method really won't work in this, particular case. I am aware of, and use, the Before Refresh and After Refresh events regularly.
    Why do you think it won't work?

    If you want to use your own javascript code you can capture the apex after refresh event using apexafterrefresh , and bind your custom logic to that event.
    See http://api.jquery.com/bind/

    But please note it is not documented
  • 6. Re: How to Wait for trigger('apexrefresh') to Complete Before Proceeding
    Joe Upshaw Journeyer
    Currently Being Moderated
    I did manage to make this call asynchronous by Herculean means...rewriting as PL/SQL and turning into an AJAX call that returns the HTML equivalent of the Report Region. Ugh!

    After doing all of that, it still didn't work for my overall purpose.

    Thanks to all who answered but, I agree now that I need to rethink this from the ground up as asynchornous call backs.

    I fought the law and the law won.

    -Joe

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points