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 capture the watch list value in a variable in servicenow

phr
Tera Contributor

Hi All,

 

How to capture watch list value in a business rule via variable

I did write the code

var watch= current.watch_list;

 

But the variable "watch" isn't capturing the watch list vale.

How to achieve this?

phr_0-1721930195944.png

 

 

 

 

5 REPLIES 5

@phr The condition is failing because the current.sys_updated_by returns a user name (e.g. abel.tuter) whereas the watchlist contains a comma separated list of user sys_ids. I recommend using the following piece of code to fetch sys_id if the user from user name.

var updated = '';
var userName = current.sys_updated_by;
var userRec = GlideRecord('sys_user');
if(userRec.get('user_name',userName)){
    updated = userRec.getValue('sys_id');
}

Add the above lines in your code and your watch list contains check will start working.

 

Hope this helps.