How can we set Watchlist Users of Catalog Task from Service Catalog Item Variable automatically?

VIKAS45
Tera Guru

How can we set Watchlist of Catalog Task from Service Catalog Item Variable automatically?

As when we set while updating Watchlist Users of Catalog Task from Service Catalog Item Variable having list of Users which is list collector field in Flow Designer it does not happen.

 

Please guide on the same.

4 REPLIES 4

Swati Sandhu
Tera Contributor

You can refer to this article by Ankur https://www.servicenow.com/community/developer-blog/using-list-collector-in-flow-designer-for-each-l... and store your watchlist users in an array and then update watchlist in catalog tasks.

Amit Gujarathi
Giga Sage
Giga Sage

HI @VIKAS45 ,
I trust you are doing great.
To address this issue, you can use a Script Step in Flow Designer to manually update the Watchlist of the Catalog Task. Here's an example code snippet that demonstrates how you can achieve this:

(function execute(inputs, outputs) {
  var taskID = inputs.task.sys_id; 
  

  var userList = inputs.item.variableName; 

  var taskGR = new GlideRecord('sc_task');
  if (taskGR.get(taskID)) {
    taskGR.watch_list = userList;
    taskGR.update();
  }
})(inputs, outputs);

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,

 

Where Should I write this script in

1)ISubFlow Input and Output

2)In Setting Flow Variables with script

3) Updating Catalog Task Watch_list field with script

4)Action Module in Servicenow

 

Also what should we select variable Type

sourav1999
Mega Guru

- Watchlist Users can be set from the Service Catalog Item Variable by creating a business rule on the sc_task table

- The business rule should be a "Before Insert" type -The script should use the current.variables.watchlist_users to get the value of the variable

- The script should set the value of the watchlist_users field to the value of the variable

- The business rule should be activated to take effect

 

For asking ServiceNow-related questions try this :

For a good and optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.

Link - https://nowgpt.ai/