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:13 PM
mark.stanger
Thanks, I thought as much. . . any reason why?
I notice there is a list of methods for the GlideRecord server side:- http://wiki.service-now.com/index.php?title=GlideRecord_Server
Is there a similar list for client scripts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:17 PM
ninnesr
I don't think one exists yet, but you can run this code in an onLoad to get the output to the Service-now logging tool (green bug in top-right).
var user = new GlideRecord('sys_user');
for(var x in user) {
jslog(x);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 05:34 PM
tony.fugere
10:24:39 (002) sc_request.do currentRow
10:24:39 (075) sc_request.do rows
10:24:39 (149) sc_request.do conditions
10:24:39 (223) sc_request.do encodedQuery
10:24:39 (297) sc_request.do orderByFields
10:24:39 (372) sc_request.do displayFields
10:24:39 (447) sc_request.do tableName
10:24:39 (522) sc_request.do ignoreNames
10:24:39 (597) sc_request.do initialized
10:24:39 (673) sc_request.do AJAX_PROCESSOR
10:24:39 (749) sc_request.do initialize
10:24:39 (825) sc_request.do addQuery
10:24:39 (901) sc_request.do getEncodedQuery
10:24:39 (978) sc_request.do deleteRecord
10:24:40 (055) sc_request.do get
10:24:40 (133) sc_request.do getTableName
10:24:40 (210) sc_request.do hasNext
10:24:40 (288) sc_request.do insert
10:24:40 (366) sc_request.do gotoTop
10:24:40 (444) sc_request.do next
10:24:40 (522) sc_request.do loadRow
10:24:40 (600) sc_request.do isDotWalkField
10:24:40 (679) sc_request.do addOrderBy
10:24:40 (759) sc_request.do orderBy
10:24:40 (839) sc_request.do setDisplayFields
10:24:40 (919) sc_request.do query
10:24:40 (999) sc_request.do setRows
10:24:41 (079) sc_request.do setTableName
10:24:41 (159) sc_request.do update
10:24:41 (240) sc_request.do _getXMLSerialized
10:24:41 (321) sc_request.do z
even some of these produce a X is not a function error
rows for example
however hasNext works
I think I'll just look into GlideAjax instead. I like that idea of rinning the DB stuff server side and just using the client stuff to manipulate the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 07:37 PM
"rows" isn't a function of client side GlideRecord, as someone mentioned - rather it is a property (I might have my terms wrong).
Assuming a client side GlideRecord variable name of "user", user.rows.length will give you the number of rows returned by the query. Note the lack of parentheses on "rows".
There should probably be a getRowCount() method added to the client side GlideRecord object that returns this. That would provide a more consistent API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2011 10:10 PM
CapaJC
I tried just .rows but not .rows.length
Thanks for that
anyway I'm now using GlideAjax and I've got another question which I'll ask in this thread