3

I want to prevent users from being redirected when they click a button and picklist value is false.

I have a custom button on Opportunity related list on account. If the value of Account type is 'OLD', users should get an error message and not redirect the page. If it's anything else, they can be redirected opportunity.

What is the best way of going about this?

Thanks, -Kenn

6

In the custom button, do something like this:

if("{!JSENCODE(Entity.Field)}"==="OLD") {
    alert("You cannot use this button on this account.");
} else {
    window.top.location.href = "(url to go to)";
}

For a picklist, you can use ISPICKVAL:

if({!ISPICKVAL(Entity.Field,'OLD')}) {
    alert("Access denied.")
}

Make sure the type is set to "Execute JavaScript".

  • Thanks a lot. Might you know the proper syntax in the situation where I have a picklist instead of a text field? Not sure how the ISPICKVAL arguments should be implemented. – Kenn K Jul 5 '13 at 20:20
  • I've updated the code to reflect how you can use ISPICKVAL for picklist values. – sfdcfox Jul 5 '13 at 21:07
  • Hi there, is there a less intrusive to display a notification instead of using alert() ? – dzh Jul 8 '14 at 13:49
  • You have full JavaScript access in a button. This means you could write as elaborate code as you wanted. Import your favorite library and show a lightbox, or change the label on the button, or do some cute little animation. The sky's the limit, though this answer was intentionally plain. – sfdcfox Jul 8 '14 at 15:26

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.