GlideAjax and usage of getRowCount()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 03:26 AM
Hi,
I am having one Assignment group reference field in Incident page.
I want to display how many members are there in that particular assignment group.
To achieve this, i created a client callable Script Include
var number = Class.create();
number.prototype = Object.extendsObject(AbstractAjaxProcessor, {
alert: function() {
var names = this.getParameter('sysparm_user_name');
var gr = new GlideRecord('sys_user_grmember');gs.log("I am starting"+names);
gr.addQuery('group',names);
gr.query();
gs.log("I am in");
var x = gr.getRowCount().toString();
gs.log(x);
return x;
}
});
And i have used the following client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var group = g_form.getReference('assignment_group');
var group_name = group.name;
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('number');
ga.addParam('sysparm_name','alert');
ga.addParam('sysparm_user_name',group_name);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
But the problem arises when I am changing the assignment group it is giving a value as 0 in alert.
Please help
- Labels:
-
Integrations
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 03:31 AM
Hi,
For getting getRowCount, best practise says do not use GlideRecord instead use GlideAggregate. Please use below script for your reference:
var count = new GlideAggregate('sys_user_grmember');
count.addQuery('group',name);
count.addAggregate('COUNT');
count.query();
if (count.next())
return count.getAggregate('COUNT');
You can refer below wiki url also for more information on GlideAggreate:
GlideAggregate - ServiceNow Wiki
Regards,
Solutioner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 03:39 AM
A small change is needed in your client script.
Current : var group_name = group.name;
Correct code: var group_name = group;
group_name should be sys_id and not name of the group because in your script inclide you are comparing with sys_id/reference field.
Regards,
Bhavesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 03:42 AM
You can also update this line :
Current : var group = g_form.getReference('assignment_group');
New : var group = g_form.getValue('assignment_group');
In case your onChange client script in on Assignment group field, just write newValue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2014 04:49 AM
Hi ,
I tried with GlideAggregate but still its not giving the correct output...