Is there a way to push a message from a HOOK to the user ?

Hello,

I have a quick question : Is there a way to push a message from a HOOK to the user ?

The purpose is easy ; during my hook, several job are processed and can return non blocking messages. Is there a way to promote thoses message to the user interface (the same way the Success message is displayed after the process for instance).

Many thanks for your help.

PS : I am aware about the sugar validation process using JS, but the message are provided by external app after insertion, and I don't want to trigger them before my record is saved.

Any solution my superheroes ??? 

Parents
  • Hi ,

    I would suggest leveraging the user "Notification" functionality. You can easily create a notification along with the message via logic hook against any user. The user will be notified immediately and the message will be visible in the notification center.

    Kind Regards,

    Junaid

  • Yes, we explored that way, but, unfortunatelly, it is not as "visual" as a popup on the screen after the save to display the "errors / warnngs" provided by the backoffice process.

    Any other idea?

  • OK. In that case, explore the following snippet solution.

    Fullscreen
    1
    SugarApplication::appendErrorMessage('Congrats Record Saved');
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This would display the message to the current user. You can use the HTML tags as well in the message to show as you like instead of simple text. 

Reply
  • OK. In that case, explore the following snippet solution.

    Fullscreen
    1
    SugarApplication::appendErrorMessage('Congrats Record Saved');
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This would display the message to the current user. You can use the HTML tags as well in the message to show as you like instead of simple text. 

Children
  • unfortunately it doesn't work ; it seems to be something dedicated to BWC modules. Am I wrong?

  • Yes, you are right. Unfortunately, this one is only for BWC modules. I was also using it for BWC modules.

    Keeping in mind what you want to achieve; I can think of the following two options from the top of my head. 

    1. As also suggested, override model save in JS. On the success of save, call custom API sending the bean information to the external solution. Then show the response or message received from that API to the user.

    2. If you still want to use the logic hooks for this purpose. Create two new fields. One for storing the message received from an external source. The second one to decide if the message already shown to the user or not. Now save the information in these fields via logic hook. After that, override the RecordView JS for that specific module and on the model sync, checks the shown bit. If the message text is not yet shown then just show the message stored in the custom field earlier and then set the bit to true so that message will not show up again on refresh of the record.

    I hope this will solve your problem. Happy Coding Slight smile

    Kind Regards,

    Junaid