Can I dynamically set reference lookup logic in a Transform Map (instead of static Choice Action)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
