How to add/append a record to List collector using GlideRecord?

runfast
Kilo Guru

I am trying to add/append a new value to List collector using GlideRecord script. My initial approach is to read/add the existing value to an array and then add the new value to same array and then write the array value back to the list collector.

so I am reaching out to see if there are any other efficient way of appending data to list collector without overwriting it.

 

thanks

 

1 ACCEPTED SOLUTION

Elijah Aromola
Mega Sage

Below is a sample script of how to append data to a list collector.

var exampleRecord = new GlideRecord("example_table"); 
// query conditions
exampleRecord.query();
if(exampleRecord.next()) {
    var listCollectorValues = exampleRecord.getValue("field_name").split(','); // split the comma separated string into an array
    listCollectorValues.push(newValue); //append the new value to the array 
    exampleRecord.setValue("field_name", listCollectorValues.toString()); //conver the array back to a string
    exampleRecord.update();
}

View solution in original post

3 REPLIES 3

Elijah Aromola
Mega Sage

Below is a sample script of how to append data to a list collector.

var exampleRecord = new GlideRecord("example_table"); 
// query conditions
exampleRecord.query();
if(exampleRecord.next()) {
    var listCollectorValues = exampleRecord.getValue("field_name").split(','); // split the comma separated string into an array
    listCollectorValues.push(newValue); //append the new value to the array 
    exampleRecord.setValue("field_name", listCollectorValues.toString()); //conver the array back to a string
    exampleRecord.update();
}

That is very nice!

Thank you very much.

khanSiddiq
Tera Contributor

We can append an existing list collector in a simple way. 
Screenshot (316).png


We can see that there is only one record in the above pasted image.

By using the syntax like : gr.work_notes_list += ',

5f74e421c0a8010e01ec0d74a7ee2cc6,2a826bf03710200044e0bfc8bcbe5de7'

Use the append symbol(+=) and make sure to start entering your sys_ids with a comma(,).
Screenshot (318).png

Screenshot (317).png