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

Ankur Bawiskar
Tera Patron
Tera Patron

@iztgokul 

how are you determining who is agent?

User with particular role? or user belonging to particular group

My thoughts

-> update BR condition as this i.e. Add big OR clause and update as this

AnkurBawiskar_0-1762859307219.png

 

-> then in BR condition check for role or group membership for logged in user (this covers your agent part)

add either of this in condition based on role or group check

!gs.hasRole('agentRole')

!gs.getUser().isMemberOf('Agent Group')

💡 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

iztgokul
Tera Contributor

Hi Ankur,

 

Agent is the person who is assigned to the case. Watchlist is Dynamic Me will not solve the issue. Because, In watchlist there can be more than one person, and my use case is when user in watchlist add any additional comments then the state changes to WIP from suspended

 

Thanks,

Gokul

 

@iztgokul 

watch list condition will work fine here

If you are in watch list along with others and you are updating the comments the BR condition will evaluate as true

Since Agent is the Assigned to of Case then update as this'

 

AnkurBawiskar_0-1762860614269.png

Watch List Dynamic Me works, see here

AnkurBawiskar_1-1762860715000.pngAnkurBawiskar_2-1762860724572.png

 

💡 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

@Ankur Bawiskar 
Subject person and Watch list person will be different.