What is the output of the script and the reason?

Suggy
Giga Sage

In my instance, there are several active Incidents.

I am running the scripts in background script.

Suggy_0-1711306348289.png

 

For below script, the output is ALWAYS printed as *** Script: INC0006919... Why? In the list view, I try to sort using number, created, updated etc, whatever I do, it ALWAYS prints INC0006919 why?

var gr= new GlideRecord("incident");
gr.addEncodedQuery("active=true");
gr.query();
while(gr.next()){
//do nothing
}
gs.print(gr.number);

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, I would suspect this is a business rule?

There is no content in the while loop, as a result your script runs a glidequery, the while loop does nothing except initiate the next() method which returns an object containing the results of the query. The script then prints the 'number' of the first record that is returned to it in the object.

swathisarang98
Giga Sage
Giga Sage

Hi @Suggy ,

 

Try keeping the "gs.print(gr.number);" inside then it will print all the active incident otherwise in your case its going inside loop but as there is nothing its not setting or getting any value 

outside while you have added a print so its print the active Incident and its giving the first  record when 'opened_by' is sorted through a to z,

 

I tried in pdi you can refer below,

swathisarang98_0-1711312308459.png

 

In list view,

swathisarang98_1-1711312376930.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

Hi Swathi,

In my script I am not sorting. In list view, what ever field I try to sort (number, created, updated), the result is always same incident number - INC0006919

@Suggy yes you are not sorting by default it will give the opened by as sorted and as you are returning only one number outside while loop its gonna give you the first active opened incident.

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang