sysparm_query returning incorrect data

Mannat Kanijow
Kilo Contributor

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

5 REPLIES 5

Markus Kraus
Kilo Sage

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

GlideRecord API Documentation 

 

HIROSHI SATOH
Mega Sage

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'));
    }
}

 

 

Bert_c1
Kilo Patron

@Mannat Kanijow 

manager_sid is not a field on the incident table OOB, unless provided by some plugin I don't have. 

Satishkumar B
Giga Sage
Giga Sage

@Mannat Kanijow Try this:

List of Incident:

SatishkumarB_0-1725127247428.png

Background Script: Return only those sysID where the short description is numberic:

SatishkumarB_1-1725127475616.png

 

 

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!!

………………………………………….......................................................................................