We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to filter for users with all capital letters in their first and / or last name

Cheski Frank
Tera Contributor

Hi!

 

In our sys_user table, we have some entries of first and last names that are all in capital letters.

 

Example: "John DOE" or "JOHN Doe" or "JOHN DOE"

 

I know that I can use the toLowerCase and toUpperCase string manipulations, but first I want to be able to find them. It doesn't matter if that is in the sys_user list with a filter or in a background script.

 

Any wisdom here?

 

Thanks and kind regards,

Cheski

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron

@Cheski Frank Here is the background script you should use to identify Names with following patterns.

1. John DOE

2. JOHN Doe

3. JOHN DOE

var gr = new GlideRecord('sys_user');
gr.query();
var userArray = [];
while (gr.next()) {   // iterate through records
   if(/^([A-Z]+\s[A-Z]+)$|^([A-Z]{1}[a-z]+\s[A-Z]+)$|^([A-Z]+\s[A-Z]{1}[a-z]*)$/.test(gr.getValue('name'))){
        var userObj = {};
        userObj.sys_id=gr.getValue('sys_id');
        userObj.name=gr.getValue('name');
        userArray.push(userObj);
   }
}
gs.info(JSON.stringify(userArray));



This script captures all such names and their sys_id and prints it in the end.

Screenshot 2023-11-04 at 10.15.46 AM.png

Please do not forget to mark the answer correct and helpful if it manages to answer your question.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron

@Cheski Frank Here is the background script you should use to identify Names with following patterns.

1. John DOE

2. JOHN Doe

3. JOHN DOE

var gr = new GlideRecord('sys_user');
gr.query();
var userArray = [];
while (gr.next()) {   // iterate through records
   if(/^([A-Z]+\s[A-Z]+)$|^([A-Z]{1}[a-z]+\s[A-Z]+)$|^([A-Z]+\s[A-Z]{1}[a-z]*)$/.test(gr.getValue('name'))){
        var userObj = {};
        userObj.sys_id=gr.getValue('sys_id');
        userObj.name=gr.getValue('name');
        userArray.push(userObj);
   }
}
gs.info(JSON.stringify(userArray));



This script captures all such names and their sys_id and prints it in the end.

Screenshot 2023-11-04 at 10.15.46 AM.png

Please do not forget to mark the answer correct and helpful if it manages to answer your question.

Cheski Frank
Tera Contributor

@Sandeep Rajput That worked like a charm, many thanks!!