- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 04:55 AM
Hi,
I am very new when I comes to writing scripts.
We have implemented Qualys integration into ServiceNow and I am after a script that I can add to the transform scripts that looks at the last logged on user data and transforms it into data ServiceNow can absorb.
The format of the data comes in like this
PARKDEAN\RobDoyle
ServiceNow of course cannot match this as its not how we display it. I need the script to remove the Parkdean\ and also split the first name and surname
We have made a custom field to store this called u_last_logged_on_user
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 05:47 AM
Hello @RobDoyle ,
Try the below code.
var inputString = source.asset_lastloggedonuser;//"PARKDEAN\RobDoyle";
var name = inputString.substring(8);
var firstName = '';
var surname = '';
// Find the point where the first name ends and surname begins
for (var i = 1; i < name.length; i++) {
if (name[i] === name[i].toUpperCase()) { // Assuming that the surname starts with an uppercase letter
firstName = name.substring(0, i);
surname = name.substring(i);
break;
}
}
target.u_last_logged_on_user = firstName + ' ' + surname;
If this response resolves your query, kindly mark it as both helpful and correct.
Thanks,
Alka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 08:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 08:11 AM
Is the "u_last_logged_on_user" field a reference field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 08:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2024 08:22 AM
Try the below updated code.
var inputString = source.asset_lastloggedonuser;//"PARKDEAN\RobDoyle";
var name = inputString.substring(8);
var firstName = '';
var surname = '';
// Find the point where the first name ends and surname begins
for (var i = 1; i < name.length; i++) {
if (name[i] === name[i].toUpperCase()) { // Assuming that the surname starts with an uppercase letter
firstName = name.substring(0, i);
surname = name.substring(i);
break;
}
}
var targetUser = '';
var userName = firstName + ' ' + surname;
var getUserID = new GlideRecord('sys_user');
getUserID.addEncodedQuery('name='+userName);
getUserID.query();
if(getUserID.next()){
targetUser = getUserID.getUniqueValue();
}
target.u_last_logged_on_user = targetUser;