sysparm_query returning incorrect data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 09:07 AM
What I am trying to do -
Show only those records on incident table where manage_sid field contains only numeric value.
manage_sid is a string field.
To achieve the same, I am running filter on incident table with query -
active=true^manage_sid>=1
But I am not getting the expected results. The query is returning all the records even the ones with alphabets or alphanumeric values.
Expected result - Records which have only numeric values.
Can someone please help me out here.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 09:27 AM
Getting all records indicates that your query is invalid.
Please manually configure a list query using the tables list view and rightclick on the last breadcrumb and select „Copy query“.
note: there is a property controlling this behavior and this has security implication for this reason it is typically considered best practice to active it (on new instances):
glide.invalid_query.returns_no_rows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 09:41 AM
I don't know if the regular expression can be used, so please try it.
active=true^manage_sid=^[0-9]+$
If the regular expression cannot be used in query, try the following code.
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addEncodedQuery('manage_sidISNOTEMPTY');
gr.query();
while (gr.next()) {
if (/^\d+$/.test(gr.getValue('manage_sid'))) {
gs.print('Incident Number: ' + gr.getValue('number') + ', manage_sid: ' + gr.getValue('manage_sid'));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 10:58 AM
manager_sid is not a field on the incident table OOB, unless provided by some plugin I don't have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 11:05 AM
@Mannat Kanijow Try this:
List of Incident:
Background Script: Return only those sysID where the short description is numberic:
var gr = new GlideRecord('incident');
gr.addQuery('active', 'true');
gr.query();
while (gr.next()) {
var shortDesc = gr.getValue('short_description'); // Replace with your manage_sid
if (/^[0-9]+$/.test(shortDesc)) {
gs.info("sysID = "+gr.sys_id +"\n"+"Short Description = "+ shortDesc);
}
}
…………………………………………........................................................................................
Please Mark it helpful 👍and Accept Solution ✔️!! If this helps you to understand!!
………………………………………….......................................................................................