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
ScriptMonkeyScriptMonkey 

Conditional Redirect in onComplete?

I have a commandButton that runs an action (confirm) and an oncomplete (window.location={!redirectURL}).  The problem is that the confirm method changes the redirectURL variable, but it's seeing the old one, probably because it parsed the variable when the button was created, not when it was clicked.  How can I have that use the new value in the variable?

 

In addition, I had a thought of doing this:

 

<apex:commandButton id="ConfirmBtn" action="{!confirm}" oncomplete="window.location=updateRedirect();" value="Confirm" />

<apex:actionFunction name="updateRedirect" action="{!updateRedirect}" />

 and the updateRedirect method returns the redirectURL's new value, but the javascript sees it as "false".

 

I'm running out of ideas, and I understand I might be approaching this totally wrong, but I'm eager to hear solutions, or how to approach this other ways.

 

 

bob_buzzardbob_buzzard

In order to get hold of an updated value from the controller, you will need to rerender part of the page.  I've handlded this in the past by setting a property in the controller that is used by javascript for a redirect.

 

While its not the exact use case, this blog should give you some pointers with regard to redirection after a request completes:

 

http://bobbuzzard.blogspot.com/2011/05/refreshing-record-detail-from-embedded.html