How to add a reference field's sys ID to a list field

P_Haug
Tera Contributor

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

Muhammad Salar
Giga Sage

@P_Haug Did you try this?