Setup Primary and Secondary Coalesce for Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi All,
I’m trying to load user data into the ServiceNow sys_user table using a transform map, and I have a specific coalescing requirement.
From the incoming payload, I need to identify existing users using a priority-based (multi-level) coalesce logic as follows:
First priority: emailAddress
Check if a user already exists with the same email address.
Second priority: employeeID
Only if no match is found using the email address, check whether a user exists with the same employee ID.
The logic must strictly follow this order—email address should always take precedence over employee ID.
If a matching user is found at either level, the existing record should be updated.
If no match is found using either field, a new user record should be inserted.
I’m unsure how to implement this kind of conditional, multi-level coalescing using a transform map in ServiceNow. Standard coalesce behavior doesn’t seem to support prioritized matching out of the box.
Has anyone implemented a similar approach, or can you suggest the best way to achieve this using transform maps?
Thanks in advance for your help.
Regards,
Debjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @DebjitGhosh
The recommended approach is to
1) Use a Transform Map Script with an onBefore script rather than standard field-level coalesce checkboxes for your requirement.
This method lets you explicitly control the sequence of actions, making sure that email is prioritized over the employee ID.
Sample code :
2) use a Field Map with a Source Script on the sys_id field.
Sample code:
- Create a New Field Map: In your Transform Map, add a new entry.
- Target Field: Set this to Sys ID
- Use Source Script: Check this box.
- Coalesce: Check this box.
- Source Script: Enter the logic below.
answer = (function transformEntry(source) { var email = source.u_email_address; // Use your source field name var empID = source.u_employee_id; // Use your source field name
var flag = false; // Check by emailAddress if (email) { var grEmail = new GlideRecord('sys_user'); grEmail.addQuery('email', email); grEmail.query(); if (grEmail.next()) {
flag= true; return grEmail.getUniqueValue(); } } // Check by employeeID (only if no email match was found)
if (!flag){ if (empID) { var grEmp = new GlideRecord('sys_user'); grEmp.addQuery('employee_number', empID); grEmp.query(); if (grEmp.next()) { return grEmp.getUniqueValue(); } }
} })(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
16 hours ago
Hi @Tanushree Maiti ,
Thank you very much for your response.
Few doubts I have, firstly do I have to implement both steps in my transform map to make it work?
In addition to that,
target.assigned_to = userGR.sys_id;
what is this assigned_to, do I have to replace this field with one of my fields, if yes which field given my requirement?
Regards,
Debjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
14 hours ago
Hi @DebjitGhosh
OnBefore transform scripts in ServiceNow are server-side scripts executed during an import, running before each source row is transformed and saved to the target table.
They are primarily used to manipulate, validate, or selectively ignore records before they enter the target table.
Whereas Field Map Source Script is used during data imports when you need to perform complex logic or data transformation on a single field that a simple direct mapping cannot.
handle
For my current and previous client , the data load logic is complex, so we have used both.
Just a addition, For onbefore script , you can update the record before transform whatever fields as per your requirement.
grUser.update()
For my cu
