Popup notification for required relationship

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • huntfarms
    Junior Member
    • Jan 2020
    • 9

    Popup notification for required relationship

    I have built a beforeSave hook to detect situation where a user is submitting a new or modified entity without relating it to another entity (many-many). The hook works but using the thrown new Error only provides a brief message that the user is neither expecting nor paying much attention to. I would like to show a popup notification with an OK button to force them to acknowledge their mistake. I've never called a popup from the PHP code and looking for some guidance.

    What is the call I make? I assume I pass the message and the need for an OK button?
    What about the action to take when the OK button is pressed? In my case I simply want the pop-up to be removed.
    Do I need to write custom client side code?
    Is there an existing call that does just what I need to do instead of something custom?

    Thank you
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    #2
    Hi,

    Getting an alert message with an OK button requires client side coding.

    PHP is a back end language, it can display stuff in the screen but not provide interactive functionality, for that, Javascript is required.

    https://www.stechies.com/display-ale...de%20language.

    You will need to create a custom detail view class for you entity and write the business logic there.

    Here are some links that might help you.

    https://forum.espocrm.com/forum/deve...ange-something

    https://docs.espocrm.com/development/custom-views/



    I would recommend that you try to catch the "error" (creating or updating an entity without the required relationship) at the client side, using an Ajax call if necessary to get that info from the back end, and then display your alert and execute the code that you want.

    What you are trying to do is not impossible but definitely requires some coding experience in both Javascript and PHP and familiarity with Espo's architecture, so be patient and search the forum for help if you get stuck.

    Good luck !
    Last edited by telecastg; 06-23-2021, 12:12 AM.

    Comment

    • huntfarms
      Junior Member
      • Jan 2020
      • 9

      #3
      Thank you - javascript savvy, not too familiar with PHP but can figure it all out. Thank you for the guidance.

      Comment


      • telecastg
        telecastg commented
        Editing a comment
        You're welcome, I think that the trickiest part is the front end, so if you're proficient in Javascript you should be fine.

        Also if you are not familiar with the Backbone framework I recommend that you get familiar with it, it will make it a lot easier to understand Espo's front end architecture.
        Last edited by telecastg; 06-23-2021, 09:15 PM.
    Working...