getRowCount is not a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:01 PM
Hi all,
**Some of the field names are different to defaults due to our build.
I'm currently writing a script to auto fill a requestor (caller) field if an organisation (department/company?) is entered and there is only one user in that organisation.
long story short I'm receiving an error when trying to use the getRowCount() function on a GlideRecord
Firbug error:
userRec.getRowCount is not a function
if (userRec.getRowCount() == 1){
//grab the confirm organisation from the form
var requestor = g_form.getReference('u_requestor')
var organisation = g_form.getReference('company')
var confirmOrg = g_form.getReference('u_confirm_organisation')
var userRec = new GlideRecord('sys_user');
if (newValue !='' && requestor.name == undefined){
//search for users with who are a member of this confirm org
userRec.addQuery('u_confirm_organisation', '=', confirmOrg.sys_id);
userRec.query();
//BROKEN!! userRec.getRowCount is not a function !?!
alert('query = '+userRec.getEncodedQuery());
if (userRec.getRowCount() == 1){
g_form.setValue('u_requestor', userName)
}
//so have to do the below. . .
var i = 0;
while (userRec.next()) {
i++;
if (i == 1){
var userName = userRec.name;
}
}
if (i == 1){
//Only one user associated with this confirm org, auto fill the requestor field
g_form.setValue('u_requestor', userName)
} else {
//more than one requestor, don't auto fill
}
}
As you can see I have a work around, but using the getRowCount() function would be much nicer.
Other functions work such as getEncodedQuery();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:05 PM
getRowCount is not available from a client-side GlideRecord query. In order to use it you'll need to use GlideAjax and run your query on the back-end, returning the row count back to the client. I'm not sure that's really simpler than what you've got here though.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:12 PM
mark.stanger
Mark beat me to it by 3 minutes, go figure. I was sitting here typing up the same thing at the same time... Mark, we could easily turn this into a single GlideAjax call though with a more sophisticated class that does all the work for us.
Also begs the question, why is this a Client Script? Does it "need" to be one? Does the user's experience require this data on the form prior to continuing on with their life? If you have no reason and can answer no to those yes/no questions, then go make it a "before" Business Rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:17 PM
tony.fugere
Yes this could be run on update.
Howerver our users tend to like to see this stuff "auto fill" before clicking save.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:08 PM
GlideRecord from a Client Script is a limited version of our GlideRecord Server object.
Since your functionality is currently "missing" on the client side and your code is technically already making at least one round-trip (AJAX) call to the server with the getReference and GlideRecord calls, think about using GlideAjax instead and get all the data you need in one trip.