Why is my custom table not working properly with .next() in GlideRecord?

rmiesen
Kilo Expert

I have created a custom table and am attempting to use it on an Inbound Email Action.   I have run into a problem however in using GlideRecord to query the table.   What is happening is that I will issue a Query and get the expected number of rows back as seen by .getRowCount().   I can issue a .next() to the query and access the first record returned without issue.   However from this point on it does not believe there are any more records.   If I run .hasNext() it returns false and if I try to use .nex() nothing changes.

 

This is my first foray into custom tables so I'm not sure if I missed some specific field needed to allow queries to properly work.   The table does not extend anything and has one reference.   Other than that it has the default values, 2 choice lists and the rest are strings.   If I change the sorting parameters I can alter which record is first without issue and using the same code I can put in an existing table and navigate the records without issue.   The table is extensible right now and autonumbered.

 

Any help would be greatly appreciated.   Here is the code I'm using, ignore that it is using a count instead of having .next() in the while loop, it is setup this way from debugging this issue.

 

var lookup = new GlideRecord('u_failed_event_rules');
lookup.query();
var count = lookup.getRowCount();
logger.logInfo('row count ' + count)
while (i < count){
         logger.logInfo('has next ' + lookup.hasNext());
         lookup.next();
         logger.logInfo('query details ' + ' policy ' + lookup.u_policy.toString() + ' client ' + lookup.u_client + ' label ' + lookup.u_schedule_label + ' type ' + lookup.u_schedule_type);
}

In the logging you can see this from the logger statements( note that the 3 query details should all be different):

row count 3

has next true

has next false

has next false

query details policy SQL_NJTOSQLC03_Daily client njtosqlc03 label TEST2 type FULL

query details policy SQL_NJTOSQLC03_Daily client njtosqlc03 label TEST2 type FULL

query details policy SQL_NJTOSQLC03_Daily client njtosqlc03 label TEST2 type FULL


1 ACCEPTED SOLUTION

I was able to solve it, the solution makes absolutely no sense to me but it is working.



All I did was change my variable for the query from 'lookup' to 'gr' and now it works.   No logic changes at all were made.


View solution in original post

16 REPLIES 16

Still no luck, think I may try to create a new table today and see if the same issue occurs.



*Edit, no luck with a new table and a new table extending task.   Just no luck.


I was able to solve it, the solution makes absolutely no sense to me but I'm going to reach out to my contacts at SN to see if they can shed some light on it.



All I did was change my variable for the query from 'lookup' to 'gr' and now it works.   No logic changes at all were made.


Jim,



I'll give this a shot in the morning and see how it goes.   Thank you for the advice.


nick_2586
Mega Contributor

instead of below code:


logger.logInfo('query details ' + ' policy ' + lookup.u_policy.toString() + ' client ' + lookup.u_client + ' label ' + lookup.u_schedule_label + ' type ' + lookup.u_schedule_type);    




Try this:


logger.logInfo('query details ' + ' policy ' + lookup.getValue('u_policy').toString() + ' client ' + lookup.getValue('u_client') + ' label ' + lookup.getValue('u_schedule_label') + ' type ' + lookup.getValue('u_schedule_type');  




Let us know if this helps.




Regards,


Nisheeth


uluerje
Mega Expert

Does it work if you set var i = 0 before the while loop?