How to push new values to a list (glide_list) type field on a table using flow designer action/script without removing the existing values?

Shubha_Prada
Tera Guru

Hi,

I have a custom table that holds the user data and the application assigned to that user. This application field type is a list type (glide list), so that whenever new application gets added to the user it should be stored in that field for that user record, and when that application is removed from the user - it also has to removed from this field.

This is done using a catalog item, when the user selects the application for an user and submits the form - after certain processes that application has to be added/removed from their user record.

As we are using flow designer for this item -
I would like to know how we can update the application value (that was selected on the form) to the application field (on the user's record in custom table)

- For adding application (CI) to the application field on user record.

I have used Update record (17) action to do it & the application reference is taken by using Get Catalog Variables action (1)

Screenshot-1

find_real_file.png

Screenshot-2

find_real_file.png

find_real_file.png

The problem I am facing is - the previous value is getting wiped off and the new value that was selected on the form is only shown up.

find_real_file.png

How can we achieve this. Please help.

Thanks in advance!

3 ACCEPTED SOLUTIONS

OlaN
Giga Sage
Giga Sage

Hi,

Since it's a GlideList you are using, the value stored are actually a comma-separated string of Sys IDs.

So to add an additional value to this list, you will need to make use of a Flow variable, and a bit of scripting.

Use the Flow variable to store the SysID of the record you want to add to the GlideList.

Then when updating the record script the new value of the list by doing something like this:

var watchList = fd_data.subflow_inputs.incident.watch_list.toString();
if (watchList == '')
  return fd_data.flow_var.id; // list is empty just add the ID
else
  return watchList += ',' + fd_data.flow_var.id; // list has values, add an additional value

 

View solution in original post

Hi @OlaN ,

Thanks for your inputs!

I tried the steps that you provided, the value is getting added to the field successfully.

Highlighted the values in the code where the variables were replaced. As I was new to the flow scripts and this syntax helped a lot. Sharing it below for reference.

Code used -

var app = fd_data.subflow_inputs.variable_name.field_name.toString();
if (app == '')
return fd_data.flow_var.flow_variable; // list is empty just add the ID
else
return app += ',' + fd_data.flow_var.flow_variable; // list has values, add an additional value
 
Could you please help how this can also be done to remove the values similar to add?
 
 
Regards,
Shubha

View solution in original post

Hi,

Sorry for the slow response...

As mentioned removing a value is a bit more complicated, but you can try something like this:

var someCommaSeparatedText = 'aa,bb,cc,dd';
var someArray = someCommaSeparatedText.split(','); // array should now look like this:  ['aa','bb','cc', 'dd'];
for (i=0; i<someArray.length; i++)
{
  if (someArray[i] == 'bb') // value you want to remove
  {
    someArray.splice(i, i);
    break; // assuming only unique values in array, will stop the looping
  }
}
someCommaSeparatedText = someArray.join(',');
gs.info('updated text: ' + someCommaSeparatedText);

return someCommaSeparatedText;

View solution in original post

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Since it's a GlideList you are using, the value stored are actually a comma-separated string of Sys IDs.

So to add an additional value to this list, you will need to make use of a Flow variable, and a bit of scripting.

Use the Flow variable to store the SysID of the record you want to add to the GlideList.

Then when updating the record script the new value of the list by doing something like this:

var watchList = fd_data.subflow_inputs.incident.watch_list.toString();
if (watchList == '')
  return fd_data.flow_var.id; // list is empty just add the ID
else
  return watchList += ',' + fd_data.flow_var.id; // list has values, add an additional value

 

Hi @OlaN ,

Thanks for your inputs!

I tried the steps that you provided, the value is getting added to the field successfully.

Highlighted the values in the code where the variables were replaced. As I was new to the flow scripts and this syntax helped a lot. Sharing it below for reference.

Code used -

var app = fd_data.subflow_inputs.variable_name.field_name.toString();
if (app == '')
return fd_data.flow_var.flow_variable; // list is empty just add the ID
else
return app += ',' + fd_data.flow_var.flow_variable; // list has values, add an additional value
 
Could you please help how this can also be done to remove the values similar to add?
 
 
Regards,
Shubha

Hi,

Sorry for the slow response...

As mentioned removing a value is a bit more complicated, but you can try something like this:

var someCommaSeparatedText = 'aa,bb,cc,dd';
var someArray = someCommaSeparatedText.split(','); // array should now look like this:  ['aa','bb','cc', 'dd'];
for (i=0; i<someArray.length; i++)
{
  if (someArray[i] == 'bb') // value you want to remove
  {
    someArray.splice(i, i);
    break; // assuming only unique values in array, will stop the looping
  }
}
someCommaSeparatedText = someArray.join(',');
gs.info('updated text: ' + someCommaSeparatedText);

return someCommaSeparatedText;

Hi I used the same script to update the list collector field without removing the old entry that were already present.

 

Though i am seeing some update in the table , but i couldn't find the new entry.

Can you please help me

I am seeing the sys id alone in the outputs.

I created the flow variables as Reference record to cmdb_ci_service