- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 09:09 AM
If I am using the below function to get the first name of the logged in user in the "Server Script" on a widget...How can I ensure the name is in the proper case (Capital first letter and lower case all the remaining letters) within this function?
(function() {
data.user = gs.getUser().getFirstName();
})();
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 10:39 AM
This works....any negative side effects using substring?
var firstName = gs.getUser().getFirstName();
data.user = firstName.substring(0,1).toUpperCase() + firstName.slice(1).toLowerCase();
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 09:25 AM
you will have to perform manipulation to that returned value
(function() {
var firstName = gs.getUser().getFirstName();
data.user = firstName.charAt(0).toUpperCase() + firstName.slice(1).toLowerCase();
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 10:04 AM
See I've tried different variations of this type of script, but I keep getting the following type error:
it lower cased "bella" properly, but seems like it didn't know how the handle the first letter A. The name in this example is "ABELLA" in the user table.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 10:39 AM
This works....any negative side effects using substring?
var firstName = gs.getUser().getFirstName();
data.user = firstName.substring(0,1).toUpperCase() + firstName.slice(1).toLowerCase();
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 08:25 PM
should be fine, no issues.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader