Need script in flow designer to add 3 user fields in watchlist

User267
Tera Contributor

Need script in flow designer to add these 3 user fields in watchlist requested item

2 REPLIES 2

Community Alums
Not applicable

Hi @User267 ,

Don't go with script directly, explore the data pill .

 in the flow designer, where you can update your record and pull the field directly into the watchlist field from the item linked on the requested item.

If that is not possible, you need to get the sysId of each field and link them with a comma to populate the watchlist via the script option at field level.

 

Within your requested item --> update record --> choose on the data pill the requested item -> item -> your custom watchlist field

 

SandeepDutta_0-1690204665756.png

 

 

Riya Verma
Kilo Sage
Kilo Sage

Hi @User267 ,

 

Hope you are doing great.

 I managed to solve this by looking up the record and replacing the watchlist with the datapill of the current watchlist + the datapill of the User ID:

RiyaVerma_0-1690204713144.png

 

Or follow below approach in flow designer :

  1. we will create a new script in the Flow Designer to handle this task. We'll use server-side scripting to manipulate the requested item's watchlist.

  2. In the Flow Designer, we'll start by creating a new action that triggers when a requested item is being processed or updated.

  3. Within this action, we will write the server-side script to add the three user fields to the watchlist. The script will use the current object to access the requested item record and modify its watchlist accordingly.

 

// Assuming 'User Field 1', 'User Field 2', and 'User Field 3' are the three user fields to be added to the watchlist
var userField1 = current.variables.user_field_1;
var userField2 = current.variables.user_field_2;
var userField3 = current.variables.user_field_3;

// Check if the user fields are not empty before adding them to the watchlist
if (userField1 && userField2 && userField3) {
  var watchList = current.watch_list.getDisplayValue(); // Get the current watchlist as a string
  var userFields = userField1 + ',' + userField2 + ',' + userField3; // Combine the user fields into a single string

  // Check if the user fields are not already in the watchlist to avoid duplication
  if (watchList.indexOf(userFields) === -1) {
    // Add the combined user fields to the watchlist
    watchList += ',' + userFields;
    current.watch_list = watchList; // Update the watchlist field in the requested item record
  }
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma