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.

When user from Watch list add additional comments state should change to WIP

iztgokul
Tera Contributor

Hi Team,

We have a Business Rule that changes the HR Case state from Suspended to Work in Progress (WIP).

Currently, the Business Rule runs when:

  • The State is Suspended

  • The Opened for or Subject person is Dynamic – Me

  • Additional comments field changes

This works fine for our current use case.

Now, we have a new requirement:
If any user from the Watch list adds Additional Comments while the case is in the Suspended state, the case should automatically move to Work in Progress.

However, if an HR Agent adds additional comments, the state should not change.

Since we can’t use the condition “Additional comments changes” directly on the Business Rule (because it triggers irrespective of who made the comment), how can we configure or script this logic properly?

 

Thanks,

Gokul

1 ACCEPTED SOLUTION

@iztgokul 

what's your actual business requirement?

earlier logic is working fine, now you just want to add 2 extra things

simply check these 2 things in filter condition

AnkurBawiskar_0-1762864332170.png

 

then use this script to further check

-> if logged in user is opened for OR logged in user is subject person OR logged in user is present in watch list AND Assigned to != Logged In user

(function executeRule(current, previous /*null when async*/) {
    var openedFor = current.opened_for;
    var subjectPerson = current.subject_person;
    var loggedInUser = gs.getUserID();
    var assignedToUser = current.assigned_to;
    var watchListUsers = current.watch_list ? current.watch_list.toString().split(',') : [];

    // Check if the logged-in user is opened_for, subject_person, or in the watch_list, and not assigned_to
    if ((openedFor == loggedInUser || subjectPerson == loggedInUser || watchListUsers.indexOf(loggedInUser) > -1) && assignedToUser != loggedInUser) {
        current.state = 'work_in_progress'; // Use your correct state value
    }
})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

@iztgokul 

what's your actual business requirement?

earlier logic is working fine, now you just want to add 2 extra things

simply check these 2 things in filter condition

AnkurBawiskar_0-1762864332170.png

 

then use this script to further check

-> if logged in user is opened for OR logged in user is subject person OR logged in user is present in watch list AND Assigned to != Logged In user

(function executeRule(current, previous /*null when async*/) {
    var openedFor = current.opened_for;
    var subjectPerson = current.subject_person;
    var loggedInUser = gs.getUserID();
    var assignedToUser = current.assigned_to;
    var watchListUsers = current.watch_list ? current.watch_list.toString().split(',') : [];

    // Check if the logged-in user is opened_for, subject_person, or in the watch_list, and not assigned_to
    if ((openedFor == loggedInUser || subjectPerson == loggedInUser || watchListUsers.indexOf(loggedInUser) > -1) && assignedToUser != loggedInUser) {
        current.state = 'work_in_progress'; // Use your correct state value
    }
})(current, previous);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 
Thank you! It’s working exactly as expected for the use case.

 

Regards,

Gokul Raj M

@iztgokul 

Glad to help.

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader