function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
we-mpwe-mp 

Call JavaScript after action executes

Hello,

I have a VF page as follows.  Included here are snippets of code:

 

 

//Command button that whose click event invokes an action that calls a webservice and creates a Result object

  <apex:commandButton id="commandButton1" value="PL">
          <apex:actionSupport event="onclick" action="{!doPLSearch}" onsubmit="openPopup()" reRender="pageBlockSection1"/>
  </apex:commandButton >

 

//hidden field to store Id of the newly created Result object

  <apex:inputhidden id="resId" value="{!resultIdAfterPLCall}" />

 

//JS to open result display VF page.

   <script>
            var newWin=null;
            function openPopup(){
                var resultId = document.getElementById("{!$Component.resId}");
                var url="/apex/PLResultDisplay"+"?id="+resultId ;
                  newWin=window.open(url, 'Popup','height=500,width=400,left=100,top=100,resizable=no,scrollbars=yes,toolbar=yes,status=no');
                if (window.focus)
                {
                    newWin.focus();
                }
                
                return false;
            }
    </script>

 

 

The doPLSearch() calls a webservice and stores the ID of the newly created Result object in 'resultIdAfterPLCall'. 

 

How can I ensure that the JavaScript gets called only after the doPLSearch() completes? 

Currently, it displays the 'PLResultDisplay VF page without any data as the Javascript executes before doPLSearch() is complete and 'resultIdAfterPLCall' is null.

 

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber

Try the "oncomplete" attribute.  By the way, you don't need the actionsupport component here. Just move those attributes to the commandButton (excluding "event", of course).

 

All Answers

mtbclimbermtbclimber

Try the "oncomplete" attribute.  By the way, you don't need the actionsupport component here. Just move those attributes to the commandButton (excluding "event", of course).

 

This was selected as the best answer
we-mpwe-mp

Thanks for your help.