Client Catalog script getRowCount() not working

servicetrout
Tera Expert

I have a catalog client script below on a catalog item, Type = onChange, Variable name = rpType, applies to Catalog Item view (checked). 

In the Background, this code:

var n = getNextTbn();
gs.print('Final TBN: ' + n);

function getNextTbn() {
var tbnCount=0; 
var gr = new GlideRecord('u_badgtbn');
gr.query();
gs.print("Nn: " + gr.getRowCount() );
tbnCount = pad(gr.getRowCount(), 9);
return tbnCount;
}

function pad(num, size) {
var s = "000000000" + num;
return s.substr(s.length-size);
}

 

Returns this: 

Script execution history and recovery


*** Script: Nn: 1
*** Script: Final TBN: 000000001

 

In my client script below, just shows the alerts

Precall...

1...

Then nothing. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var rpIdentifier = g_form.getValue('rpIdentifier');
if ( rpIdentifier.length < 2 ) {
alert ('Precall...');
var nNext = getNextTbn(); 
alert ("nNext: " + nNext);
g_form.setValue('rpIdentifier', nNext );
alert ('postCall... ' , nNext );
}
}

function getNextTbn() {
var tbnCount=0; 
var gr = new GlideRecord('u_badgtbn');
gr.query();
alert ("1...");
alert("Nn: " + gr.getRowCount() );
alert ("2...");
tbnCount = pad(gr.getRowCount(), 9);
alert ("3...");
return tbnCount;
}

function pad(num, size) {
var s = "000000000" + num;
return s.substr(s.length-size);
}

 Any idea why that would be the case?  Table u_badgtbn has read and write ACLs set to public.  Nothing showing up in any of the logs on this.

 

 

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Lot of GlideRecord function wont work in Client Script. That's why you need to use Glideajax for such use cases.


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

Lot of GlideRecord function wont work in Client Script. That's why you need to use Glideajax for such use cases.


Please mark this response as correct or helpful if it assisted you with your question.

servicetrout
Tera Expert

Ah!  Good to know.  Thank you. 

 

benlittle
Tera Expert

From client side, you can't use getRowCount(). However, gr.rows.length will return what you are looking for without a GlideAjax call.

Ironically, if you use the callback function, getRowCount() does work.

gCI.query(myCallbackFunction);

    function myCallbackFunction(gCI) {
          gCI.getRowCount();    //Does return the correct value
    }