Background script for printing the INC no.'s that ends with 0(zero)

amit71
Tera Contributor

Background script for printing the INC no.'s  that ends with 0(zero). Please guide this how to achieve.

eg: INC1234430

1 ACCEPTED SOLUTION

Ricky S Larsson
Tera Guru

You could achieve this after the query as well by using the regex test function

var gr = new GlideRecord('incident');
var regex = /[0]$/;
gr.query();
while(gr.next()){
    var endsWithZero = regex.test(gr.number);
    if(endsWithZero)
        gs.print(gr.number);
}

View solution in original post

10 REPLIES 10

Harish KM
Kilo Patron
Kilo Patron

Hi sample script

var query = 'numberENDSWITH0'; //ends with 0
var inc = new GlideRecord('incident');
inc.addEncodedQuery(query);
inc.query();
while(inc.next())
{
gs.info("INC"+inc.number);
}

Regards
Harish

amit71
Tera Contributor

Hi @Harish KM,

 

Can you suggest script without using the addEncodedQuery().

 

Thanks,

Amit

Try the below without encoded query

var inc = new GlideRecord('incident');
inc.addQuery("number",'ENDSWITH',0);
inc.query();
while(inc.next())
{
gs.info("INC"+inc.number);
}

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this in query. You can do this on your own

Query -> numberENDSWITH0

Once you have this query you can use this in addEncodedQuery()

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader