Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

CAPITAL letters(upper case) change to (lower case)

Mohamed Aashik
Tera Contributor

my problem is that people enter the name in full caps (ex: MICHAEL) instead of (ex: Michael)
is there a way to change all the caps?

4 REPLIES 4

RaghavSh
Mega Patron

there are 2 string operation toLowerCase() and toUpperCase()

You can use them.


Raghav
MVP 2023
LinkedIn

Community Alums
Not applicable

Hi @Mohamed Aashik ,

the field where you want to make the first letter uppercase and rest lowercase?

The basic script to do something like that is as follows:

 

var str = "test";
//Making sure that everything is converted to lowercase first
str = str.toLowerCase();
//Making the first character uppercase
var newStr = str.charAt(0).toUpperCase() + str.slice(1);

//result for this code -> str: test, newStr: Test

 

 

Saurabh Gupta
Kilo Patron

Please try using below script

 

function getPropercase(str)
{
    if(str)
    return str.charAt(0).toUpperCase()+str.toLowerCase().substring(1);
    else
    return "";
}

gs.info(getPropercase("SAURABH"))
gs.info(getPropercase("saurabh"))
gs.info(getPropercase("SaUrAbh"))

Thanks and Regards,

Saurabh Gupta

Saurabh Gupta
Kilo Patron

Hi @Mohamed Aashik 

 

 


Thanks and Regards,

Saurabh Gupta