coalesce on two fields in transform map inserting new records

Abhishek Kumar8
Tera Contributor

I need to coalesce on two fields where one field is the Account(reference to customer_account) field and the other is the User(reference to the user(sys_user)) field.

it should check for both Account and the User field then it should update another field "Technology" ( glide list)record, but for me even if I try to load the same data new entry is created instead of ignore,

Also if the same Account and User are present but with different Technology values, it should update the existing record instead of inserting a new record.

field map - choice action - ignore set for these three fields.

Target table : User account relationship

Tried with Onbefore script:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    gs.log("action" + action, "tech1");

    var techname;
    var queryString = 'u_aacount=' + source.u_client + '^u_user.email=' + source.u_email;
    gs.log("techname" + queryString, "tech1");
    var graccrel = new GlideRecord('u_user_account_relationship');
    graccrel.addEncodedQuery(queryString);
    graccrel.query();
    if (graccrel.next()) {
        //if ((action == "update") || (action == "insert")) {
            var technology = graccrel.x_csm_technology;
                gs.log("techname" + techname +"tech" +technology, "tech1");
            var graccrel1 = new GlideRecord('x_csm_technology');
            graccrel1.addQuery('sys_id', technology);
            graccrel1.query();
            if (graccrel1.next()) {
                techname = graccrel1.u_technology;
                gs.log("techname" + techname, "tech1");

            }

            if (techname == source.u_technology) {
                source.sys_import_state_comment("Duplicate entry, Record with the same Account User combination exist in the system");
                //log.error("setabortaction");
                gs.log("technamecompare" + techname, "tech1");
                //source.setAbortAction(true);
                ignore = true;
            }
        //}
    }

 

 

 

})(source, map, log, target);

 

Any help on this is really appreciated.

 

Thanks,

Abhishek

 
9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

since both the target fields on which coalesce is done are reference type; did you specify the Referenced value field name in the field map?

share the field map screenshots.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Yes, I've specified the reference value field name in the field map for both fields.

Still, it's inserting a new record every time for data load.

Thanks,

Abhishek

Hi,

if either value is not found it will insert.

If both the values are found then it will update

Did you check the incoming data?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar , yes, the new record is inserted in the import set table and target table as well. it seems choice action is not working.

also before script is not working, if needed.