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

addEncodedQuery using copy query not picking correct records

vinitha3
Tera Guru

var qry ="stateNOTIN3,6,7,10";

qry += "^business_service=44fb09b16fa96a00e40e0f1aea3ee42c";

qry += "^sys_created_onBETWEEN";

qry += "javascript:gs.dateGenerate('2016-09-01','00:00:00')";

qry += "@javascript:gs.dateGenerate('2016-12-31','23:59:59')";

qry+= "^sys_updated_onRELATIVELE@dayofweek@ago@14";

var gr = new GlideRecord('incident');

gr.addEncodedQuery(qry);

gr.query();

Whats wrong in this script?

Bu URL it works fine but when I Glide Record, it does not work.

1 ACCEPTED SOLUTION

chirag_bagdai
ServiceNow Employee

Hi Vinitha, I think the issue is with "NOTIN" vs "NOT IN". Please give a space in "NOTIN" query and see if that works. Regards, Chirag Bagdai


View solution in original post

5 REPLIES 5

reginabautista
Kilo Sage

The code looks good, i've tested this in my instance and I am getting results. Try checking the rowCount and see what you are getting..



var qry ="stateNOTIN3,6,7,10";


qry += "^business_service=44fb09b16fa96a00e40e0f1aea3ee42c";


qry += "^sys_created_onBETWEEN";


qry += "javascript:gs.dateGenerate('2016-09-01','00:00:00')";


qry += "@javascript:gs.dateGenerate('2016-12-31','23:59:59')";


qry+= "^sys_updated_onRELATIVELE@dayofweek@ago@14";


var gr = new GlideRecord('incident');


gr.addEncodedQuery(qry);


gr.query();


gs.log(gr.getRowCount())


By URL, its zero records, by row count it shows 414 records..



Thank You,



Vinithabanu Kaliamurthi| Senior Application Software Developer | CDM Smith | Tel: (617) 452-7705 | e-mail: vinithabanuk@cdmsmith.com<mailto:vinithabanuk@cdmsmith.com>


chirag_bagdai
ServiceNow Employee

Hi Vinitha,



You can use gr.getEncodedQuery() function after the query() and then you can compare the generated Query with URL.



I hope this will help.



Regards,


Chirag Bagdai


chirag_bagdai
ServiceNow Employee

Hi Vinitha, I think the issue is with "NOTIN" vs "NOT IN". Please give a space in "NOTIN" query and see if that works. Regards, Chirag Bagdai