Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

my Script not working

David Cross
Tera Expert

Here incident created on ' 2022-07-18 ' is not been shown but all other incident are shown.

 

what i want is => on incident created "2022-07-18" should be shown

 

var g = new GlideAggregate('incident');
g.addQuery('sys_created_on','ON','2022-07-18');
g.setLimit(1);
g.query();
while(g.next()){
gs.print(g.number);
}

 

3 REPLIES 3

Community Alums
Not applicable

Hi @David Cross ,

 

Add the below code

 

var g = new GlideAggregate('incident');
//change to your required date
g.addEncodedQuery("sys_created_onON2024-04-24@javascript:gs.dateGenerate('2024-04-24','start')@javascript:gs.dateGenerate('2024-04-24','end')");
g.query();
while (g.next()) {
    gs.print(g.number);
}

Additionally you can create query using filter in list view and pass that query in addEncodedQuery() function.

 

AnandMahajan_0-1725440371051.png

 

 

If this solves your query mark this as correct and helpful.

 

Anand

Sandeep Rajput
Tera Patron
Tera Patron

@David Cross Please try the following script. Since code editor on community is not vary good at handling javascript: I am also attaching the screenshot here.

Screenshot 2024-09-04 at 2.23.17 PM.png

Here is the code.

 

var g = new GlideRecord('incident');
g.addEncodedQuery("sys_created_onON2022-07-18@javascript:gs.dateGenerate('2022-07-18','start')@javascript:gs.dateGenerate('2022-07-18','end')");
g.setLimit(1);
g.query();
while(g.next()){
gs.print(g.number);
}

Community Alums
Not applicable

Hi @David Cross 

You can try the script below. It works properly on my PDI.

 

var gb = new GlideRecord('incident');
gb.addEncodedQuery("sys_created_onON2022-07-18@javascript:gs.dateGenerate('2022-07-18','start')@javascript:gs.dateGenerate('2024-04-17','end')");
gb.setLimit(1);
gb.query();
while(gb.next()){
    gs.print(gb.number);
     //gs.print(gb.getRowCount());
}