- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 03:22 PM
Posting this code thinking it might be usefull to anyone: i have 5 incidents satisfying the below query
I wanted to write a back script to get number of records satisfying below query
var inc = new GlideRecord("incident");
inc.addEncodedQuery("active=true^incident_stateNOT IN6,7^short_descriptionSTARTSWITHInvalid Assigned To^u_requested_for=879a48fc0a0a3caa01b7dc8eba6a7593^incident_state=1^state=1");
inc.query();
gs.print(inc.getRowCount());
output : 5
*************************************************************
If you want to print record numbers of each incdient in the result then use below script:
var inc = new GlideRecord("incident");
inc.addEncodedQuery("active=true^incident_stateNOT IN6,7^short_descriptionSTARTSWITHInvalid Assigned To^u_requested_for=879a48fc0a0a3caa01b7dc8eba6a7593^incident_state=1^state=1");
inc.query();
while(inc.next())
{
gs.print(inc.number);
}
out put : prints all 5 numbers of incidents
***************************************************************
If you want to print number of records and also each record number then use below code
var inc = new GlideRecord("incident");
inc.addEncodedQuery("active=true^incident_stateNOT IN6,7^short_descriptionSTARTSWITHInvalid Assigned To^u_requested_for=879a48fc0a0a3caa01b7dc8eba6a7593^incident_state=1^state=1");
inc.query();
gs.print(inc.getRowCount());
while(inc.next())
{
gs.print(inc.number);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 07:07 PM - edited 06-27-2023 07:10 PM
Hi Vahini,
Please do not use GlideRecord for fetching counts as currently you might be working on small database but on larger scale you should use GlideAggregate()
For Example:
var gaIn = new GlideAggregate('incident');
gaIn.addEncodedQuery("active=true^incident_stateNOT IN6,7^short_descriptionSTARTSWITHInvalid Assigned To^u_requested_for=879a48fc0a0a3caa01b7dc8eba6a7593^incident_state=1^state=1");
gaIn.addAggregate('COUNT');
gaIn.query();
while(gaIn.next()){
gs.addInfoMessage(gaIn.getAggregate('COUNT'));
}
If you found my answer useful, please mark as correct answer.
Thanks,
Kaustubh Kulkarni

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 07:07 PM - edited 06-27-2023 07:10 PM
Hi Vahini,
Please do not use GlideRecord for fetching counts as currently you might be working on small database but on larger scale you should use GlideAggregate()
For Example:
var gaIn = new GlideAggregate('incident');
gaIn.addEncodedQuery("active=true^incident_stateNOT IN6,7^short_descriptionSTARTSWITHInvalid Assigned To^u_requested_for=879a48fc0a0a3caa01b7dc8eba6a7593^incident_state=1^state=1");
gaIn.addAggregate('COUNT');
gaIn.query();
while(gaIn.next()){
gs.addInfoMessage(gaIn.getAggregate('COUNT'));
}
If you found my answer useful, please mark as correct answer.
Thanks,
Kaustubh Kulkarni