- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 05:15 AM
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..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 07:36 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 09:04 PM