Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Can I dynamically set reference lookup logic in a Transform Map (instead of static Choice Action)?

EdanR
Tera Contributor

I’m working on a ServiceNow Transform Map where a source field maps to a reference field on the target table (e.g., company → core_company). The target table includes both customers (customer=true) and vendors (vendor=true), but I only want to link vendor-type companies during the import.

Currently, the Choice Action setting on the field map is static and doesn’t allow row-level logic. My question:

  • Is there a way to dynamically control which record gets linked (or skip linking) based on attributes of the target record (e.g., vendor=true)?
  • Can this be done via a Source script on the field map, or is there another recommended approach?

Goal: Prevent accidental linking to a customer-type company when importing vendor data.

Any best practices or examples for implementing this logic would be appreciated!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@EdanR 

using field map script is also possible

something like this and it will pick only vendor=true company record

answer = (function transformEntry(source) {

    var companyName = source.company_value; // Adjust field name as needed
    if (!companyName) {
        return -1; 
    }

    // Lookup ONLY vendor companies
    var gr = new GlideRecord('core_company');
    gr.addQuery('name', companyName); // Or your lookup field: 'u_vendor_code', etc.
    gr.addQuery('vendor', true);
    gr.query();
    if (gr.next()) {
        return gr.sys_id.toString(); // Link this vendor
    }

    return '';

})(source);

AnkurBawiskar_0-1767603064288.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@EdanR 

don't use Field map script.

Handle this logic using onBefore transform script

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Ankur Bawiskar
Tera Patron

@EdanR 

using field map script is also possible

something like this and it will pick only vendor=true company record

answer = (function transformEntry(source) {

    var companyName = source.company_value; // Adjust field name as needed
    if (!companyName) {
        return -1; 
    }

    // Lookup ONLY vendor companies
    var gr = new GlideRecord('core_company');
    gr.addQuery('name', companyName); // Or your lookup field: 'u_vendor_code', etc.
    gr.addQuery('vendor', true);
    gr.query();
    if (gr.next()) {
        return gr.sys_id.toString(); // Link this vendor
    }

    return '';

})(source);

AnkurBawiskar_0-1767603064288.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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