Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Flow Designer variables

cgedney
Giga Guru

I am trying to build an inbound email flow designer. What I need to be able to do is add a group of users to the watchlist on the incident form. What I tried to do originally was do a lookup of the group and then do a for each item and assign that to a variable. I cannot find a way to assign the values to a variable recursively so that they become a comma separated list. So then I tried to build a sub flow and assign the values to the output variable, but it doesn't allow you to attach the values in a list to the output variable. Any help is much appreciated.

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

I have created a custom action which can be used in all tables as below:

1) Inputs:

Group Name : name of group so that users for this group can go to watchlist

Table Name: Table name

Table Sys Id: Where the watch list has to be updated.

 

2) Script:

(function execute(inputs, outputs) {
// ... code ...
  var inc = new GlideRecord(inputs.tableName);
  inc.addQuery('sys_id',inputs.tableSysId);
  inc.addActiveQuery();
  inc.query();
  if(inc.next()){
    var arr = [];
  	var grp = new GlideRecord('sys_user_grmember');
    grp.addQuery('group.name',inputs.groupname);
    grp.query();
    while(grp.next()){
    	arr.push(grp.user+'');
    }
    inc.watch_list = arr.toString();
    inc.update();
  }
  outputs.ids = arr.toString();
  
})(inputs, outputs);

 

3) Outputs:

 

 

Tested Result:

 

 

Attached is the xml of the Action:

 

Thnks,
Ashutosh

View solution in original post

5 REPLIES 5

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure script step to add users to watch list in your flow.

 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/referen...

 

Managing Glide Lists

 

Regards,

Sachin

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

The group is always common or it is dynamic?


Thanks,
Ashutosh

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

I have created a custom action which can be used in all tables as below:

1) Inputs:

Group Name : name of group so that users for this group can go to watchlist

Table Name: Table name

Table Sys Id: Where the watch list has to be updated.

 

2) Script:

(function execute(inputs, outputs) {
// ... code ...
  var inc = new GlideRecord(inputs.tableName);
  inc.addQuery('sys_id',inputs.tableSysId);
  inc.addActiveQuery();
  inc.query();
  if(inc.next()){
    var arr = [];
  	var grp = new GlideRecord('sys_user_grmember');
    grp.addQuery('group.name',inputs.groupname);
    grp.query();
    while(grp.next()){
    	arr.push(grp.user+'');
    }
    inc.watch_list = arr.toString();
    inc.update();
  }
  outputs.ids = arr.toString();
  
})(inputs, outputs);

 

3) Outputs:

 

 

Tested Result:

 

 

Attached is the xml of the Action:

 

Thnks,
Ashutosh

This is awesome Ashutosh! Thank you so much! I'm kinda new to ServiceNow coding and I thought it should have gone into a Subflow. I hadn't tried it in an Action yet.