
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 05:52 PM
Hi all,
I'm very new to coding in ServiceNow so I'm sure this is a rudimentary ask but I have the following scenario.
I have an import table u_sample_import with a field which holds primary user emails u_primary_user_email. I'm attempting to use this value to set 'assigned_to' in a transform map. In order to do this I need to query the sys_user table and get matching records based on the 'sys_user.email' field.
Once those matching records are found I need to get the data from sys_user.name and set it as the value of the field in the target table.
I'm running this from a transform map field script on create.
answer = (function transformEntry(source) {
var gr = new GlidRecord('sys_user');
var userName = '';
gr.addQuery('email', source.u_primary_user_email);
gr.query();
userName = gr.name;
return userName; // return the value to be put into the target field
})(source);
Am I even in the ballpark?
Thanks,
Daniel
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 05:55 PM
try below
answer = (function transformEntry(source) {
var userName = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('email', source.u_primary_user_email);
gr.query();
if(gr.next()){
userName = gr.sys_id;
}
return userName; // return the value to be put into the target field
})(source);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 12:56 PM - edited 03-21-2024 12:57 PM
Can you give me example of the source email field? Is it comma separated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 10:15 PM
Hello,
Yes it is comma separated, But the below code doesn't work for me. Could you please help me where I went wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 04:15 AM
Have you got solution for this? If yes then please share with me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 04:14 AM
Can you reply on Ruthika0319