
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 11:28 AM
Issue: 'Assigned to' on the alm_hardware table is being populated with the same user for every record.
import field: u_surname (formatted: 'last name'<comma><space>'first name')
target field: Assigned to
Source Script:
answer = (function transformEntry(source) {
if (source.u_surname) {
var user = new GlideRecord('sys_user');
user.addQuery('last_name' + ", " + 'first_name', source.u_surname);
user.query();
if (user.next()) {
return user.sys_id;
} else {
return "";
}
}
})(source);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 04:56 PM
Because my script was populating the field, I thought the query was working. Then realized it was not not working at all. Below is the script that works:
answer = (function transformEntry(source) {
if (source.u_surname) {
var user = new GlideRecord('sys_user');
x = source.u_surname.split(',')
user.addQuery('last_name', x[0]);
user.addQuery('first_name', x[1].trim());
user.query();
if (user.next()) {
return user.sys_id;
} else {
return "";
}
}
})(source);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 04:56 PM
Because my script was populating the field, I thought the query was working. Then realized it was not not working at all. Below is the script that works:
answer = (function transformEntry(source) {
if (source.u_surname) {
var user = new GlideRecord('sys_user');
x = source.u_surname.split(',')
user.addQuery('last_name', x[0]);
user.addQuery('first_name', x[1].trim());
user.query();
if (user.next()) {
return user.sys_id;
} else {
return "";
}
}
})(source);