
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:25 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 09:48 PM
@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.
Please do not forget to mark the answer correct and helpful if it manages to answer your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 09:48 PM
@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.
Please do not forget to mark the answer correct and helpful if it manages to answer your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 10:44 PM
@Sandeep Rajput That worked like a charm, many thanks!!