Display error message from a snippet in the OnError action

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I have a button that runs an action which is a javascript snippet. This snippet returns a promise. It resolves the promise if successful and rejects it if it isn't. I want to be able to add an onError action to the snippet action that will display the error message that is returned in the rejection of the promise.

I have the onError event working and it displays when the snippet code fails. The issue is, that it only displays the text that is put in the Message field of the action. Is there some sort of merge syntax I can use to pull out the text that I return from the rejected promise? 
Photo of Keith Heard

Keith Heard

  • 122 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
A few ideas. 

1. Put the entire error message in your initial javascript snippet in the reject branch.   This way you can pass variable text directly into the message. 

2. If you really want to use a separate on error action - your reject branch could update a field with the value you want to show - and then you could use merge syntax to display the field value. 
Photo of Keith Heard

Keith Heard

  • 122 Points 100 badge 2x thumb
Thanks for the reply. I'll probably end up using your 2nd idea. That's probably cleaner from a ux perspective than showing the error through the block UI show message action.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Sounds good.  Hope it works for you 
Photo of Velvel Marasow

Velvel Marasow

  • 452 Points 250 badge 2x thumb
Any property passed in as a parameter to the Deferred.reject() is available in template syntax in the onError Message, so:

dfd.reject({message : 'This is a message that the user will see.'});


Will block the UI and display the message passed in to the reject call to the user.