glide_list

Kanika4
Tera Contributor

I need to write logic to keep a glide_list field sync with the related list on that form. In other words, there is a table Y in the related lists of table X, all the records of table Y should get displayed on table X list field. (Table X and Y have m2m mapping).

Could anyone please help..

1 ACCEPTED SOLUTION

Hi Kanika,

Try below scripts and do testing

sample script below for the insertion

var rec = new GlideRecord('table X');
rec.addQuery('sys_id', current.<fieldX>);
rec.query();
if(rec.next()){

var listArray = rec.<listField>.toString().split(',');

var valueOfY = current.<fieldY>;

listArray.push(valueOfY.toString());

rec.<listField> = listArray.toString();
rec.update();

}

Sample script for deletion

var rec = new GlideRecord('table X');
rec.addQuery('sys_id', current.<fieldX>);
rec.query();
if(rec.next()){

var listArray = rec.<listField>.toString().split(',');

var valueOfY = current.<fieldY>;

var indexOf = listArray.indexOf(valueOfY);

listArray.splice(indexOf, 1);

rec.<listField> = listArray.toString();
rec.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Kanika4
Tera Contributor

@Ankur Bawiskar  Thanks