How to count number of incident closed by particular user in current day and number to set at "Count Number" field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2016 02:54 AM
Hi All,
As I asked how to count the number of incident closed by particular user in 1 day(current or past) .And that count I want to set on one I field created to "Count Number " to repersent field.
Note :
Is any table that have count the number of incident closed as like Metrics.
How to count the number that closed .
and How to set that number on mentioned field.
What i tried is
"
function onLoad() {
var get = new GlideRecord('incident');
//get.addQuery('priority', 1);
//gr.addQuery('caller_id',caller);
get.addQuery('state','7');
get.query();
//var count=0;
if (get.next()){
//while (get.next()){
count=count+1;
}//
alert ("Its working as per requirement");
}
alert ("it going to set the value");
g_form.setValue('u_count_number',Count_number);
}
"
So Please help in this .
Regards,
Gaurav Rai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2016 03:44 AM
Hi Gaurav,
I had the same req once.
When you glide record the incident form after addQuery and query you can add this.
Var b;
Var count=0;
If(get.next()){
While(get.next()){
b=get.state;
Count=count+1;
}
}
If(b=="Clossed")
alert(count);
}
The rest of your code seems fine.
By this whenever yo open your form it will give you the count of all clossed incidents. It worked for me. There may be a scope of modification.
Please share if you face any issue.
Regards,
Mayur

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2016 10:58 AM
Gaurav,
you will have to use GlideAjax and do your server side manipulation in the script include.
onLoad client script:
function onLoad() {
var ga = new GlideAjax('GetClosedIncidentsCount');
ga.addParam('sysparm_name','getCount');
ga.getXML(callBack);
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_count_number',answer); //Set your count field here.
}
}
Script include: name your script include as "GetClosedIncidentsCount" only. Check the client callable check box and co[py the following script as is.
script:
var GetClosedIncidentsCount = Class.create();
GetClosedIncidentsCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function(){
var gr= new GlideRecord('incident');
gr.addEncodedQuery('state=7^closed_atONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)'); // closed today
gr.addQuery('closed_by',gs.getUserID()); //closed by the logged in user
gr.query();
return gr.getRowCount().toString();
},
type: 'GetClosedIncidentsCount'
});
Thanks,
Abhinay
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2016 11:44 AM
Just a little trim...
Since your "counting" do a GlideAggregate instead (new GlideAggregate('incident');
just so you keep the "do calculations" use GlideAggregate mindset. Even if GlideRecord works as well.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2017 09:12 AM
Hey Goran,
I have a customer that has a few reporting challenges with aggregates (counts) filtering and sorting (i.e. Top 40 Incidents by Category and location sorted by the Totals of each Category ( or conversely by the Totals of each location) We managed a work around with a Bar chart report showing the table data but...
In addition, they have some reports that require count conditions - i.e. If # of cases / incidents is greater than 3 ...
Could I use this method to add a field that populates with the count total and then just sort by that field?
Any recommendations on how to do this?
Jay McDonald