script for changing letter cases

dsmit
Kilo Contributor

I am wondering if anyone has a script that they would not mind sharing that I can run that will go and make sure that all of the CIs within the CMDB are all capital letters. Right now there is a combination of lower and upper cased CIs and I am not sure the easiest way to address this would be?

5 REPLIES 5

Oliver D_sereck
Giga Expert

Hi dsmit,

Since you can always use most of the functions from Javascript, you can definately use the toUpperCase() function:
string.toUpperCase()

Reference:
http://www.w3schools.com/jsref/jsref_touppercase.asp

To do this in Service Now, you could create a Business Rule (before Update) on the cmdb_ci table, that as soon as someone tries to save, it forces the CI Name to capital letters.

To update all existing CI's, you will need to create a temporary Business Rule which goes over all CI's in the CMDB_CI table and changes their names to capitals

Cheers,
OD


benn23
ServiceNow Employee
ServiceNow Employee

You can run this in background scripts to update all existing records. Note I've added 'setWorkflow(false)' and 'autoSysFields(false)' to prevent triggering business rules and updating the system fields.

var ci = new GlideRecord('cmdb_ci');
ci.query();
while(ci.next()){
ci.setWorkflow(false);
ci.autoSysFields(false);
ci.name = ci.name.toUpperCase();
ci.update();
}

Then create a BR that fires before insert or update:
conditions: current.name.changes() && !current.name.nil()
script:
current.name = current.name.toUpperCase();


ShaneBrazeal
Tera Contributor

I would recommend using a Field Transformations - http://wiki.service-now.com/index.php?title=Field_Transformations

You will have to activate the Field Normalization plugin, but this provides a way to select fields on tables and define whether you want the string to be all upper case, lower case, etc and some other options and generates the scheduled jobs to run and update existing records too. Definitely the best way to go!


Julia7
Mega Contributor

this post is almost a year but I give it a try 🙂

How about if we want only the first lettre capital?
I have a Hiring form wich automaticly create the user in the service-now user table
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 and keep only the first letter capital?