- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2016 03:13 AM
Hi All,
In incident table I have column "abc" and "ijk". "ijk" is a dependent field on "abc". So, I'm grouping "abc" and getting the count on "ijk". Ex. If I'm grouping "abc" and getting the count of "ijk" I will get 3.
Also I have a table "XYZ" and "incident". On "XYZ" table I'm writing a client script. The result I need is when "XYZ" table is loaded I need to aggregate the count of column "ijk" to get count and compare the count with remaining values and put the highest count in "rst" column of "XYZ" table.
How can I achieve this?
I tried for sample purpose:
Working
var inc = new GlideRecord('incident');
inc.query(incResponse);
function incResponse(inc) {
while(inc.next()) {
alert("hi");
}
}
For getting count I tried but not working.
var inc = new GlideAggregate('incident');
inc.addQuery('active', 'true');
inc.addAggregate('COUNT', 'category');
inc.query(incResponse);
function incResponse(inc) {
while (inc.next()) {
var category = inc.category;
var categoryCount = inc.getAggregate('COUNT', 'category');
alert("category "+category, "categoryCount "+categoryCount);
}
}
Can any one help me in resolving this.
Thanks,
Sowmya.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2016 05:30 AM
You can do it in a GlideAJAX:
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ajax = new GlideAjax('getIncCount');
ajax.addParam('sysparm_name', 'getCount');
ajax.getXML(IncCount);
function IncCount(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
Script Include:
Client Callable: true
var getIncCount = Class.create();
getIncCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function(){
var inc = new GlideAggregate('incident');
inc.addQuery('active', 'true');
inc.addAggregate('COUNT', 'category');
inc.query();
var answer = '';
while (inc.next()) {
var category = inc.category;
var categoryCount = inc.getAggregate('COUNT', 'category');
answer += "\ncategory " + category + ", categoryCount " + categoryCount;
}
return answer;
},
type: 'getIncCount'
});
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2016 05:30 AM
You can do it in a GlideAJAX:
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ajax = new GlideAjax('getIncCount');
ajax.addParam('sysparm_name', 'getCount');
ajax.getXML(IncCount);
function IncCount(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
Script Include:
Client Callable: true
var getIncCount = Class.create();
getIncCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function(){
var inc = new GlideAggregate('incident');
inc.addQuery('active', 'true');
inc.addAggregate('COUNT', 'category');
inc.query();
var answer = '';
while (inc.next()) {
var category = inc.category;
var categoryCount = inc.getAggregate('COUNT', 'category');
answer += "\ncategory " + category + ", categoryCount " + categoryCount;
}
return answer;
},
type: 'getIncCount'
});
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2016 09:26 PM
Hi Mike,
Thanks a lot......
Can't we do all this process in client script without "GlideAjax"?
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2016 04:26 AM
I could not make it work. I had to go with GlideAJAX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2016 06:04 AM
GlideAggregate doesn't have a client-side version like GlideRecord. However, even if a client-side version existed, you would still want to use a call-back function. Using GlideAjax ensures that you are following ServiceNow's defined scripting best practices. I'm sure your users will appreciate it