-3

I need a confirmation alert box to pop up if shipping is set to 0. If the user pressed ok it should redirect to the quote, if the user presses cancel it should stay on the current page.

I am using a custom page detail button set to OnClick JavaScript on a Standard Quote Layout.

  • Could you add your code and clarify you question because it is not clear at the moment what the problem is. – Sergej Utko Mar 20 '14 at 9:42
  • I don't have any code currently. I tried to modify some examples but they didn't seem to work. I have edited to the question to hopefully clarify this. – Carl S Mar 20 '14 at 9:45
  • Are you wanting to work with a Visualforce page or a standard page layout? – Simon Lawrence Mar 20 '14 at 9:50
  • Standard page layout – Carl S Mar 20 '14 at 9:53
  • ah, well. I just wrote you up a VF solution. It would definitely help us to include more info in questions! – Simon Lawrence Mar 20 '14 at 9:57
2

The broadest answer I can give to the broadest question would be something like:

On your Visualforce commandButton, set the onclick attribute to be a javascript function call

<apex:commandButton onclick="return showConfirmation();" action="{!SendOrder}" value="Send Order"/>

Then in your Visualforce page, have yourself a bit of javascript, within an apex:output panel to do the javascript alert box. If OK is selected the page will "continue" on to the action command of the button, if false is selected, the user is returned to the page:

<apex:outputPanel id="sendScript">
  <script type="text/javascript">
  function showConfirmation() {
    var orderSize = '{!orderSize}';
    if(orderSize == 0) {
      return confirm('That is zero');
    }
  }
  </script>
</apex:outputPanel>

There is a merge field in there which examines the orderSize.. but in order to keep this in line with the current state of the order object, it needs to be rerendered whenever this value changes..

Therefore, finally, on your input field for the order size, or whatever component determines/changes ordersize, add a rerender="sendScript" or an actionSupport to rerender this Javascript panel (which re-merges the orderSize value)

<apex:actionSupport event="onchange" rerender="sendScript" />

Do this whereever orderSize can be altered and the javascript block will be redrawn so the logical comparison remains relevant.

2

Managed to resolve this using the following code on a Page Detail button set to OnClick Javascript:

if ('{!Quote.ShippingHandling}' == "£0.00")
{
if (confirm('Are you sure you want to quote with no shipping cost?')) {
window.location = 'APEX URL/?id={!Quote.Id}';
}
} else {
window.location = 'APEX URL/?id={!Quote.Id}';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.