The best way to calculate field value between modules

Could you please suggest the best way to calculate field values efficiently?
Below is my example.

I have got 2 modules:

  1. Module ‘Employee’ - field:
    a. HourlyRate(number input)

  2. Module ‘Timesheet’ – fields:
    a. WorkedHours (number input),
    b. WorkedHoursValue → which should be calculated: Employee.HourlyRate * Timesheet.WorkedHours

I have prepared a workflow to calculate this value, but I have a problem with saving it – action is triggered 10 times instead of 1.
The workflow is triggered by actions in the ‘Timesheet’ module: either after creation or after an update. At the end I use ‘Compose record update’ function to save ‘Timesheet’ record with new value. And this function triggers the action/ workflow again. In the result record gets updated 10 times. I’ve noticed this in the revision numbers.

Is there a way I can solve this issue or maybe I did something wrong in here?

1 Like

@karolkavip - I’m having the same challenge. The “after update” trigger ends up in a never ending loop if you update the record that triggered the workflow during the workflow. I can’t help but think that there’s a way to elegantly escape that. Were you able to find a solution on your end? Thank you!

@karolkavip and @kenderson

Why are you using an afterCreate / afterUpdate trigger? Without seeing the full workflow, you should try using a beforeCreate / beforeUpdate trigger to avoid the loop.

In the example you provide, you know the Employee and the WorkedHours, so you can calculate the WorkedHoursValue – before create or update.

Regards
Mark

2 Likes

I would second what @mark wrote.
Use a before create/update trigger and set values accordingly. Since it’s a before trigger, you don’t need to save the record variable explicitly.

Alternatively, you could use an interval trigger to run it once a day or every few hours; I doubt you need the numbers reflected immediately

1 Like