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

Valmik Patil1
Kilo Sage

Hello @Hritik ,

Try adding condition as below

ValmikPatil1_0-1720162631247.png

Thanks,

Valmik Patil

 

Yashsvi
Kilo Sage

Hi @Hritik,

please check below script:

// Check if state is "Awaiting User Info" and last updated 6 days ago
if (current.state == 'Awaiting User Info') {
    var updatedDate = new GlideDateTime(current.sys_updated_on);
    var sixDaysAgo = gs.daysAgoStart(6);
    if (updatedDate < sixDaysAgo) {
        // Perform actions (e.g., change state to "Resolved" and trigger notification)
        current.state = 'Resolved';
        current.update();

        // Trigger notification to the requestor
        // Example: gs.eventQueue('my.notification.event', current, current.requested_for);
    }
}

Thank you, please make helpful if you accept the solution. 

Could you please let me know How do I register an event for the notification ?

Hi @Hritik 

refer this:
https://docs.servicenow.com/bundle/washingtondc-mobile/page/administer/tablet-mobile-ui/task/configu...

https://docs.servicenow.com/bundle/washingtondc-build-workflows/page/administer/platform-events/task...

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand.