Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to add dynamic condition in Business Rule for records updated 6 days ago ?

Hritik
Tera Expert

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

8 REPLIES 8

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 ?

Satishkumar B
Giga Sage
Giga Sage

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.

Hi @Satishkumar B 

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 ?

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 ?