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

Hello @Ankur Bawiskar ,

 

Is is possible to execute without using addEncodedQuery().

 

Thanks,

Amit

You can try

addQuery('number', 'ENDSWITH', '0');

instead of

addEncodedQuery(); 

Hi,

any reason you don't want to use addEncodedQuery()?

yes it's possible as mentioned by Jaspal

Regards
Ankur

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

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);
}

Hi Richard,

running the GlideRecord.query() without any condition will fetch all records from the DB.

Then you are applying the regex ,