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

Mihir Mohanta
Kilo Sage

1.Write business rule in the "rm_release" table.


2. Script:



var gr = new GlideRecord("rm_feature ");


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


gr.query();


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


while(gr.next()) {


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


}




Check log.You can find the count of the number of features associated with a release.



Thanks,


Mihir


Hi Mihir,



I had thought of doing this, but couldn't decide on what condition should the BR fire.


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


Thanks Mihir,



This approach is giving the correct result!



I'm still confused though, as to why the glideRecord into the release form was not able to give the result.



Thanks, at least you found a workaround



Regards,


Sarah