Background Scripts

Akshat8
Tera Contributor

Hello Everyone , I want to write a background script to print last 5 incidents created yesterday and also we have to implement it only using background script. Anyone has any solution? Thanks in advance.

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hello @Akshat8  ,

Pls try this script:

 

bgss.png

 

@Akshat8  , Please mark my answer as "Accept as Solution" and "Helpful." If it works for you.

 

Thank you.

View solution in original post

Uday_Kumar
Giga Guru

Hi @Akshat8  How are you ?

I am pasting my code please have a look.

var gr=new GlideRecord('incident');
gr.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
gr.orderByDesc('sys_created_on');
gr.setLimit(5);
gr.query();
while(gr.next())
{
    gs.print("The Incident Number is "+gr.number);
}

If my solution helps you please mark my Solution Accepted and Helpful.

Thanks and regards

Uday Kumar Valapudasu

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hello @Akshat8  ,

Pls try this script:

 

bgss.png

 

@Akshat8  , Please mark my answer as "Accept as Solution" and "Helpful." If it works for you.

 

Thank you.

Thank you so much for the help.

Community Alums
Not applicable

yw🙂

Gopi Naik1
Kilo Sage

Hi @Akshat8  ,

 

Try to use below script for your requirement.

 

var inc=new GlideRecord('incident');
inc.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
while(inc.next()){
gs.print(inc.number);
}

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi