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
Jeff FontasJeff Fontas 

Cannot get actionStatus onStop to execute javascript

I am trying to have a JavaScript function executed after the completion of a save method in my Apex controller using an apex:actionStatus tag, but I can't seem to be able to get it to work.  Here is the portion of the code I am working with that isn't working properly:

<apex:page showHeader="false" controller="AddCodesController">
    <script>

    function CloseWindow() {
        console.log('hey');
        window.opener.refreshParent();
        window.close()
    }
    </script>
    <apex:form id="addCodesForm">
        <apex:pageBlock title="Add Related Codes" id="myData">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save & Close" status="closer"/>
                <apex:commandButton value="Cancel" onclick="window.close()"/>   
                <apex:actionStatus startText="(Saving...)" stopText="" onStop="CloseWindow();" id="closer"/>
            </apex:pageBlockButtons>  
       </apex:pageBlock>
    </apex:form>
</apex:page


I put the console.log() in there just to see if it was firing, and I can't get it to show up.  I have searched and looked at probably 5 or 6 different examples and it seems like I have written this properly, but I can't for the life of me figure out what is going wrong.  Any help would be greatly appreciated it.
Best Answer chosen by Jeff Fontas
Shrikant BagalShrikant Bagal
Hello Jeff,

Please try
You just have "oncomplete for commandButton"
----------------------------------------------------------------------------------------------------------------------------
<apex:page showHeader="false" controller="AddCodesController">
    <script>
    function CloseWindow() {
        console.log('hey');
        window.opener.refreshParent();
        window.close()
    }
    </script>
    <apex:form id="addCodesForm">
        <apex:pageBlock title="Add Related Codes" id="myData">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save & Close" status="closer" oncomplete="CloseWindow();"/>
                <apex:commandButton value="Cancel" onclick="window.close()"/>   
                <apex:actionStatus startText="(Saving...)" stopText="" id="closer"/>
            </apex:pageBlockButtons>  
       </apex:pageBlock>
    </apex:form>
</apex:page
----------------------------------------------------------------------------------------------------------------------------

Please mark as best answer so it will help to other who will serve same problem.
​Thanks! 

All Answers

Shrikant BagalShrikant Bagal
Hello Jeff,

Please try
You just have "oncomplete for commandButton"
----------------------------------------------------------------------------------------------------------------------------
<apex:page showHeader="false" controller="AddCodesController">
    <script>
    function CloseWindow() {
        console.log('hey');
        window.opener.refreshParent();
        window.close()
    }
    </script>
    <apex:form id="addCodesForm">
        <apex:pageBlock title="Add Related Codes" id="myData">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save & Close" status="closer" oncomplete="CloseWindow();"/>
                <apex:commandButton value="Cancel" onclick="window.close()"/>   
                <apex:actionStatus startText="(Saving...)" stopText="" id="closer"/>
            </apex:pageBlockButtons>  
       </apex:pageBlock>
    </apex:form>
</apex:page
----------------------------------------------------------------------------------------------------------------------------

Please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
This was selected as the best answer
Jeff FontasJeff Fontas
This worked! Thank you.