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.

onForeignInsert in ServiceNow

mayanksinghrath
Giga Contributor

scenario if i have two reference fields and both are referring to different tables how to use onForeigninsert because in that we only use target so how will servicenow know which table to refer

2 REPLIES 2

KumkumM
Tera Contributor

 The onForeignInsert event script is processed at the start of the creation of a related, referenced record, before the record is created.
The onForeignInsert script runs separately for each reference field mapping, not once for all fields together.

// This script runs when a referenced record does not exist
// and ServiceNow is about to create it

if (target.getTableName() == 'sys_user') {

// Logic for User table
target.user_name = source.caller_id;
target.first_name = source.first_name;
target.last_name = source.last_name;

} else if (target.getTableName() == 'sys_user_group') {

// Logic for Group table
target.name = source.assignment_group;
target.description = "Created via Transform Map";

}

 

but what if i have two reference fields and both are referencing the same table then how will servicenow know which field i am talking about