The CreatorCon Call for Content is officially open! Get started here.

How to fetch the January and February month open records.

vinod6
Tera Contributor

How to fetch the January and February month open records through script.

Please write a script above script

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

By adding a query to your script you can specify what dates you want to get.

Providing an example below:

var incGR = new GlideRecord('incident');
incGR.addEncodedQuery("sys_created_on>=javascript&colon;gs.dateGenerate('2023-01-01','00:00:00')^sys_created_on<=javascript&colon;gs.dateGenerate('2023-02-28','23:59:59')");
incGR.query();

while (incGR.next()){

    // your logic/actions here
}

SANDEEP28
Mega Sage

@vinod6 Follow below steps 

 

1) Go to list view of table from where you want to fetch records. Here I am going for an incident table. Add you filter like open records for January and February month.

 

SANDEEP28_0-1693376978307.png

 

2) Right click on filter and copy query

 

SANDEEP28_1-1693377054218.png

sys_created_onBETWEENjavascript&colon;gs.dateGenerate('2023-01-01','00:00:00')@javascript&colon;gs.dateGenerate('2023-02-28','23:59:59')^stateIN1,2,3,4

 

3) Put the copied query as parameter in addEncodedQuery method as below 

var incGR = new GlideRecord('incident');
incGR.addEncodedQuery("sys_created_onBETWEENjavascript&colon;gs.dateGenerate('2023-01-01','00:00:00')@javascript&colon;gs.dateGenerate('2023-02-28','23:59:59')^stateIN1,2,3,4");
incGR.query();
while (incGR.next()){
//write you logic here
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

 

SANDEEP28
Mega Sage

@vinod6If I could help you with your Query then, mark my answer as Correct !!