Proper Case First Name in a Widget Server Script

Steven Parker
Giga Sage

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
1 ACCEPTED SOLUTION

@Ankur Bawiskar 

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Steven Parker 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

See I've tried different variations of this type of script, but I keep getting the following type error:

StevenParker_0-1746551016845.png

 

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

@Ankur Bawiskar 

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

@Steven Parker 

should be fine, no issues.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader