Restricting Updates to "Locked" Invoices via workflows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laimonas
    Senior Member
    • May 2021
    • 221

    Restricting Updates to "Locked" Invoices via workflows

    Hi,

    Currently, when an Invoice is "Locked", it cannot be edited via the UI. However, it is still possible to update an Item in a "Locked" Invoice using workflows or custom hooks.

    Is there a way to completely prevent any updates to a "Locked" Invoice or its Items through the system itself, without relying on the "isLocked" parameter?

    This would prevent unauthorized changes, as workflow reports might contain errors, such as missing the "isLocked" parameter or setting it incorrectly.
  • yuri
    Member
    • Mar 2014
    • 8747

    #2
    The easiest way is to create a beforeSave hook for the Invoice entity type.

    PHP Code:
    if ($entity->get('isLocked') && !$entity->isAttributeChanged('isLocked')) {
        throw new 
    \Espo\Core\Exceptions\Conflict("Cannot change locked record.");


    ​​​https://docs.espocrm.com/development/hooks/
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • Laimonas
      Laimonas commented
      Editing a comment
      Thank you, it works!
Working...