Business Rule Keep looping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:13 PM
im running a business rule to run after a value changes, but it keeps looping , i checking the values of two fields and send them in an event but this keeps looping which is causing me to have more than i need notifications.
var plannedHours = current.resource_plan.planned_hours;
var extention = current.resource_plan.extension_value;
var newTotalHours = plannedHours + extention;
gs.eventQueue('PlannedHoursOver10', current, plannedHours.toString(), newTotalHours.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:45 PM
Hi @ServNowDev ,
Hope you are doing well.
Could you please share the condition that you have in place for this BR
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:55 PM
thanks for the reply here are my conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:53 PM
Hi @ServNowDev,
As per the Scripts, there is no any loop/ recursion. make sure the correct condition is applied to business rule When to run sections.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 10:02 PM
HI @ServNowDev ,
I trust you are doing great.
Please find the updated code
(function executeRule(current, previous /*null when async*/) {
// Check if the condition is met before proceeding
if (current.resource_plan.planned_hours.changes() || current.resource_plan.extension_value.changes()) {
// Update the fields without triggering the business rule again
current.setWorkflow(false); // Disable workflow to prevent additional business rule execution
current.resource_plan.new_total_hours = current.resource_plan.planned_hours + current.resource_plan.extension_value;
current.update(); // Persist the changes to the record
gs.eventQueue('PlannedHoursOver10', current, current.resource_plan.planned_hours.toString(), current.resource_plan.new_total_hours.toString());
}
})(current, previous);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi