How to add a reference field's sys ID to a list field
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 12:23 PM
I'm working with a client and need to be able to reference old companies that were previously assigned to an INC. It's for SLA reasons, but where I'm getting in stcuk is trying to add the previous companies on teh record, to a list field also on the table. The list field is a custom field called Previous Company list (u_previous_company_list).
I've created an After business rule when the company changes, but it doesn't seem to be working. It's been a while since I've needed to script something like this so I'm not sure where I messed up.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (current.company) {
var compSysId = current.company;
var arr = [];
var prevComps = new GlideRecord('core_company');
prevComps.addQuery('sys_id', 'IN', compSysIds);
prevComps.query();
while (prevComps.next()) {
arr.push(prevComps.toString());
}
current.u_previous_company_list = arr.toString();
}
})(current, previous);
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2025 05:28 AM
@P_Haug Did you try this?