Comparing two tables in a transform script to coalesce

heathers_
Kilo Sage

Coalescing on a string field where the source field and target field need data manipulation to match. Running into an issue when using the manipulated fields, unable to compare records in both tables to match and coalesce.

 

1. Remove "J" from source field (WORKS!)

2. Remove leading two characters from target field (WORKS!)

--->>> ISSUE: Comparing records in both tables to coalesce

answer = (function transformEntry(source) {

    var source_record= new GlideRecord('u_customer_account_import');
    source_record.get('sys_id', source.sys_id);
    var site_code = source_record.u_site_code.replace(/J/g, '');


   var list = [];    
   var target_record= new GlideRecord('customer_account');
    target_record.addQuery('customer', 'true');
    target_record.query();
   while (target_record.next()){
    var str = target_record.name.toString();
    var newStr = str.substring(2);
    list.push(newStr);
}

    if (list == site_code) {

        return site_code ; 
    }
})(source);

 

 

 

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Looks like your site_code is a string while the list variable is an array.

You should use indexOf to check if the site code 

if (list.indexOf(site_code)>-1)

{

return site_code;

}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

SanjivMeher
Kilo Patron
Kilo Patron

Looks like your site_code is a string while the list variable is an array.

You should use indexOf to check if the site code 

if (list.indexOf(site_code)>-1)

{

return site_code;

}


Please mark this response as correct or helpful if it assisted you with your question.

Thank you! This worked.

Also, needed to add the first two characters back to the return value.

 

    if (list.indexOf(site_code) > -1) {

        return "00" + site_code;
    }