Search code examples
moqui

How to show customized error message in moqui?


When I create a new record in WorkEffort and when I provide the workEffortId that already exists, then an error message displayed is:

(Error in update for:INSERT INTO WORK_EFFORT (WORK_EFFORT_ID, WORK_EFFORT_TYPE_ENUM_ID, STATUS_ID, WORK_EFFORT_NAME, DESCRIPTION, LAST_UPDATED_STAMP) VALUES (?, ?, ?, ?, ?, ?))

Now I want to show a customized error message to user instead of the technical one above, like : "This workEffortId already exists".

Thanks in advance :-)


Solution

  • Just write a bit of code to check for the error condition, and then add an error message to the MessageFacade error list. In Groovy code this would be something like ec.message.addError(...) or .addValidationError(...). In XML Actions you can use the message or return action elements to do this (a return with error="true" plus a message is the most common way to do this in a service, for example).

    For more details see the MessageFacade API JavaDoc and the XML Actions schema documentation on moqui.org, or the relevant sections in the Making Apps with Moqui book.