Create query instead of RegX
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I got the following RegX and need help how to use or transfer it for an encoded query to get all matching CI names (server names with class "Windows Server" from table "cmdb_ci_server").
[i,I][m,M][c,C][i,I,t,T,p,P][e,E]0[0,d,D,f,F,a,A,p,P] [0,a,A,b,B][0-9][a,A][0-9][0-9]
Example for a result (server name): imcie0000a00
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I don't know that you can use regex in a GlideRecord query, so you may have you loop through all of the class, pushing the matching results to an array.
var matchArr = [];
var svr = new GlideRecord('cmdb_ci_server');
svr.addQuery('sys_class_name', 'cmdb_ci_win_server');
svr.query();
while (svr.next()) {
var regex = new RegExp("[i,I][m,M][c,C][i,I,t,T,p,P][e,E]0[0,d,D,f,F,a,A,p,P] [0,a,A,b,B][0-9][a,A][0-9][0-9]");
if (regex.test(svr.name)) {
matchArr.push(svr.name);
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello @Brad Bowman ,
Regex is working server side script :
var regex = /^[iI][mM][cC][iItTpP][eE]0[0dDfFaApP][0aAbB][0-9][aA][0-9][0-9]$/;
var gr = new GlideRecord('cmdb_ci_server');
gr.addQuery('sys_class_name', 'cmdb_ci_win_server');
gr.query();
while (gr.next()) {
var name = gr.getValue('name');
//added this to check regex work or not : var name = "imcie0000a00"
gs.print(name)
if (name && name.match(regex)) {
gs.print('Matched CI: ' + name);
}
else{
gs.print("not matched")
}
}
