- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 03:40 PM - edited 04-22-2025 09:15 AM
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);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 03:48 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 03:48 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2025 09:18 AM
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;
}