Field Map Not Working Properly

Ariomar de Deus
Tera Contributor

Hey guys, I'm creating a field map with the code below, but there are a few issues that are causing the code to not work properly.

When I check Coalesce, all records are skipped and this error message appears:
"Unable to resolve target record, coalesce values ​​not present:"

 

The other issue is that when I uncheck Coalesce, it inserts all records but doesn't insert existing records, creating new, empty records with new sys IDs.

(function transformEntry(source) {
    if (source.u_cod_subitem) {
        var a1 = new GlideRecord("x_bdb_5wa_000004_teste");
        a1.addQuery("cd_sub_item", source.u_cod_subitem);
        a1.query();
        if (a1.next()) {
            return a1.sys_id.toString();
        }
    }
    return "";
})(source);

Could someone help me find a solution for this?