Old Related Bank Record Not Reset When Changing Bank in Workflow

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brotherlouie
    Junior Member
    • May 2023
    • 26

    #1

    Old Related Bank Record Not Reset When Changing Bank in Workflow

    Hi,

    I’m using EspoCRM 9.1 with the Advanced Pack.

    I have a custom entity called Virman, which has a many-to-one relationship with the Bank entity.

    Here’s my setup:

    When a new Virman record is created, a Workflow updates the related Bank record (for example, adds or subtracts amounts based on transaction type).

    When a Virman record is updated, the Bank record is recalculated.

    When a Virman record is deleted, the Bank record is recalculated again to remove its effect.

    All these actions work perfectly except when I change the related Bank.

    Here’s the issue in detail:

    I create a Virman record linked to Bank A with an amount of 1000 USD.
    → Bank A correctly shows 1000 USD in its total field.

    Later, I edit the same Virman record and change the linked bank from Bank A to Bank B, then save.

    After saving:

    Bank A still shows 1000 USD (it should reset to 0).

    Bank B also shows 1000 USD.
    So both banks temporarily show the same value.

    When I manually click “Recalculate formulas” on the Bank entity, everything becomes correct:

    Bank A resets to 0.

    Bank B correctly shows 1000 USD.

    It seems that formula recalculation or Workflow logic is not automatically triggered for the previously related Bank record when the Virman → Bank link changes.

    Is there any way to automatically trigger recalculation (or a Workflow) for both:

    the old related Bank (to reset its value), and

    the new related Bank (to update with the new amount)?

    Or is there a recommended approach to handle this case when the relation field is changed in Workflow?

    Thanks a lot for your help!
  • victor
    Active Community Member
    • Aug 2022
    • 1038

    #2
    You didn't show what your Workflows look like, but the most obvious workaround in my opinion is to create https://docs.espocrm.com/administrat...ows/#scheduled, which would run periodically on records included in the List Report (which you will use for this Workflow).

    Comment

    • brotherlouie
      Junior Member
      • May 2023
      • 26

      #3
      Hi Victor. You're right, I didn't add the workflow. I'm sharing it now. The strange thing is that I created a report (list) according to your suggestion. Then, when I run it as a scheduled task, it works correctly. But with my current workflow, I always have to do the calculation manually.
      Attached Files

      Comment

      • victor
        Active Community Member
        • Aug 2022
        • 1038

        #4
        Originally posted by brotherlouie
        Hi Victor. You're right, I didn't add the workflow. I'm sharing it now. The strange thing is that I created a report (list) according to your suggestion. Then, when I run it as a scheduled task, it works correctly. But with my current workflow, I always have to do the calculation manually.
        For this case, instead of Trigger Type "After record created or updated", try using "Signal -> @update":

        Click image for larger version

Name:	image.png
Views:	0
Size:	12.7 KB
ID:	122122
        When a Virman record is deleted, the Bank record is recalculated again to remove its effect.
        For those records that have been deleted, you should use "Signal -> @delete":

        Click image for larger version

Name:	image.png
Views:	0
Size:	12.4 KB
ID:	122123

        Comment

        • brotherlouie
          Junior Member
          • May 2023
          • 26

          #5
          Unfortunately, even though I tried this, it didn't work for me.

          Comment


          • victor
            victor commented
            Editing a comment
            I checked it myself before advising you.
            Try disabling old workflows and creating new ones with "Trigger Type -> Signal".

          • victor
            victor commented
            Editing a comment
            Alternatively, create 2 workflows with "Trigger Type -> Scheduled" type. Each of the workflows will use its current List Report, where the correct records are collected. The frequency of execution of this Workflow will depend on the "Scheduling" field in the workflow itself and on "Administration > Scheduled Jobs > Run Scheduled Workflows."
        Working...