How to add dynamic condition in Business Rule for records updated 6 days ago ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 11:51 PM
Hi Community,
Please find my requirement below:
I need to change the status of legal Request which is in Awaiting User Info state and last updated 6 days ago to "Resolved" and trigger a notification for Requestor.
I created a after Update BR for this. However, I cannot add the dynamic condition in BR that record must be updated 6 days ago.
Could you pleaseee help me here ?
Do I need to write a query in Condition field of BR or write a method in script ?
Thanks in Advance,
Hritik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:11 AM
Hi @Yashsvi ,
I have implemented the same but it still doesn't work. Records which are in awaiting state and updated months ago are still not resolved.
Is it because i am using "After update" BR ? What type of BR should I select for this ?
Could you please help ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 01:16 AM
Hi @Hritik
try this:
(function executeRule(current, previous) {
var status = current.state; // Replace 'state' with your actual field name for status
var updatedDate = new GlideDateTime(current.sys_updated_on); // Get last updated date
var now = new GlideDateTime(); // Current date and time
var daysSinceUpdate = GlideDateTime.subtract(now, updatedDate).getDayPart(); // Calculate days since last update
// Check if status is "Awaiting User Info" and last updated 6 or more days ago
if (status == 'Awaiting User Info' && daysSinceUpdate >= 6) {
// Update status to "Resolved"
current.state = 'Resolved'; // Replace 'state' with your actual value for Resolved status
// Trigger notification to requestor (adjust as per your notification setup)
gs.eventQueue('legal_request.resolved', current, current.requestor); // Replace with your actual notification event and recipient field
gs.info('Legal Request updated to Resolved status and notification triggered.');
}
})(current, previous);
--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2024 09:41 PM
Thanks for the response.
Could you please also guide how do I set the notification from BR ?
Do I need to register event for this in event registry ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:10 AM
Hi @Satishkumar B ,
I have implemented the same but it still doesn't work. Records which are in awaiting state and updated months ago are still not resolved.
Is it because i am using "After update" BR ? What type of BR should I select for this ?
Could you please help ?