Trigger a BR after all records are updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:26 AM
Hello,
I’m facing an issue with my Business Rule, and I’m not sure how to resolve it.
Here’s the scenario:
I have a questionnaire for a Risk Assessment (4 questions).
When a user fills it out, it creates or updates records in the asmt_assessment_instance_question table.
I have a Business Rule (BR) that runs after insert or update on this table.
The BR looks at the "value" fields on the asmt_assessment_instance_question records (for example 2, 5, 3 and 1), sums them up, divides by four, and based on the result, it updates the "impact" field on the Risk record for which the Assessment was created.
The problem:
The BR is triggered multiple times—once for each record update (since there are 4 questions = 4 records being updated in the table).
As a result, it sometimes calculates the final value incorrectly because it might pick up outdated values during the process.
I’m not sure how to handle this.
Should I consider using a scheduled job? Or is there a way to trigger the BR only after all 4 records have been updated?
I would really appreciate it if someone could spare a moment to guide me on the best approach.
Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 03:55 AM
I would change the Business Rule to run after insert/update on the asmt_assessment_instance table, when State changes to Complete, then do a GlideRecord to get the values from the question table. This will ensure the values are what were submitted, not when the form is present and/or input is being received.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:01 AM
Hello Brad,
thanks a lot for your idea.
I should have explained more.
The goal is to count the values of the responses before the Risk assessment is submitted (in a Complete state). Customer wants to fill/complete the Inherent assessment, save it, then they want to do the audit and then to complete the Residual assessment.
That is why I created this BR on the asmt_assessment_instance_question table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 04:40 AM
As you found out, one record for each question is created on the question table when the assessment instance is created, initially with an empty value. If you want the impact field updated before the assessment is submitted, it will likely be inaccurate. You could add a check in your script so that it doesn't run if any of the values are empty, if you think that would help in your scenario.