- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016 06:10 PM
Hi all,
I was able to import the middle initial from AD and place it in the Middle Name field in ServiceNow but the problem I am having is that when a user doesn't have a middle name, the sys_user.name adds an extra space between the first and last name.
I don't know too much about scripting but this is what I did.
Out of the box the sys_user.name is calculated using the following:
if (current.first_name.nil() && current.last_name.nil() && !current.name.nil()) {
var names = current.name.toString().split(" ");
if (names.length > 1) {
current.first_name = names [0];
names.shift();
current.last_name = names.join(" ");
} else
current.last_name = names [0];
}
if(current.first_name.nil()) {
current.last_name;
} else {
current.first_name + ' ' + current.last_name;
}
I then modified the the calculated value to include an additional "if" statement at the end
if(current.middle_name.nil()) {
current.first_name + ' ' + current.last_name;
} else {
current.first_name + ' ' + current.middle_name + ' ' + current.last_name;
}
The name field now displays the middle initial if the user has one but the problem now is that if the user doesn't have one it creates an extra space between the first and last name. Is there a way to remove the extra space if the user doesn't have a middle name?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2019 11:26 AM
I did somewhat find a solution to display the middle initial but I decided not to roll it out because displaying it would have caused confusion for our end users.
When searching for a user using a reference field it would require our end users to know a person's middle initial when searching for them. If they just typed the person's first and last name it wouldn't find the right person until they inputted a middle initial.
But the script to bring in the middle initial is below if you want to try it out.
//checks to see if the user has a middle name. If not display first name, last name and email
if(current.middle_name.nil()) {
current.first_name +" "+ current.last_name +" ("+ current.email +")";
}
else {
current.first_name + ' ' + current.middle_name + ' ' + current.last_name +" ("+ current.email +")";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2019 09:38 AM
How did you pull the middle name attribute from LDAP import ? I looked through my available fields and middle name is not visible in the list dropdown for source field, we are having an issue where we need to map the middle initial from AD to the middle_name field on sys_user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2019 11:11 AM
For our organization at least we don't put the full middle name in AD instead we put their middle initial. The field that is used in AD for our user's middle initial is "initials". Hopefully that helps you out.