- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 02:25 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 03:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 02:34 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 03:09 AM
Hi Anurag,
Tried this, result is same. The same issue i can even replicate on my personal instance.
coounter = 1 | *** Script |
Features = 1 | *** Script |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 02:48 AM
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());
}
Thanks
Akash
PS hit like if helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 03:22 AM
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