What is the output of the script and the reason?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:54 AM - edited 03-25-2024 05:45 AM
In my instance, there are several active Incidents.
I am running the scripts in background script.
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 12:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 01:33 PM
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,
In list view,
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 05:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 05:52 AM - edited 03-25-2024 05:53 AM
@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