Could you please suggest the best way to calculate field values efficiently?
Below is my example.
I have got 2 modules:
Module âEmployeeâ - field:
a. HourlyRate(number input)
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?
@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!
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.
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