Why Gliderecord's getRowCount is not giving accurate result?

sarahmustakim
Kilo Contributor

Hi All,

I'm trying to get the count of the number of features associated with a release. I have written an after business rule on Insert, on the rm_feature table with the below code:

(function executeRule(current, previous /*null when async*/) {

  // Add your code here

  var gr = new GlideRecord("rm_release");

gr.addQuery("sys_id", current.parent);

gr.query();

  gs.log("Features = "+ gr.getRowCount());

while(gr.next()) {

    gs.log("INSIDE WHILE Features = "+ gr.getRowCount());

}

})(current, previous);

Both the logs are giving gr.getRowCount() result as 1...even if there are multiple features already associated with the release.

Please assist.

Thanks,

Sarah

1 ACCEPTED SOLUTION

Hi Sarah,



You are right.Your business rule should be in "rm_feature" table. Just change the script as below.


Change the script to:



(function executeRule(current, previous /*null when async*/) {


    // Add your code here


  var gr = new GlideRecord("rm_feature");


gr.addQuery("parent", current.parent);


gr.query();


  gs.log("Features = "+ gr.getRowCount());


while(gr.next()) {


    gs.log("INSIDE WHILE Features = "+ gr.getRowCount());


}


})(current, previous);




Thanks,


Mihir


View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Run this and see how many times is it going in while



var c=0;


var gr = new GlideRecord("rm_release");


gr.addQuery("sys_id", current.parent);


gr.query();


  gs.log("Features = "+ gr.getRowCount());


while(gr.next()) {


c++;


}


  gs.log("coounter = "+ c);



I believe both will still be the same only.


-Anurag

Hi Anurag,



Tried this, result is same. The same issue i can even replicate on my personal instance.



coounter = 1*** Script


Features = 1*** Script

akashsrm100
Kilo Guru

Hi sarah


Check your condition you have put   without condition its running fine


  var gr = new GlideRecord('rm_release');


//gr.addQuery("sys_id", current.parent);


gr.query();


  gs.log("Features = "+ gr.getRowCount());


while(gr.next()) {


    gs.log("INSIDE WHILE Features = " + gr.getRowCount());


}


find_real_file.png


Thanks


Akash


PS hit like if helps


Hey Akash,



I didn't understand your reply earlier.


The addQuery condition is a direct sys_id comparison. There is a Parent field referencing the release on the Feature form.


Without the condition its just counting the number of features in the system. Yes even i got 25 as result.



Thanks,


Sarah