Post

2 followers Follow
0
Avatar

Using $NumberOf to get the total number of objects

Is this what it is intended for?

I did 

$groupRequirementsbyAssignedTo

$AssignedTo ($count)

but the numbers didn't make any sense.

Am I misunderstanding this key word?  If so, is there a way to get the total number of  objects (requirements?) in a group (or repeat)?

Thanks for any advice!

Tom Tomasovic Answered

Please sign in to leave a comment.

9 comments

0
Avatar

Hi Tom,

$count shows how many times you've iterated through a repeat loop. It starts out at one and increases by one each time you start processing a new item.  What you want is the $NumberOf keyword. This can be combined with a where clause, for example, $numberOfUseCases where Priority = 1.  In your example, you'll want $numberOfCurrentGroup to show the number of items in the group currently being processed.  Let me know if you have any problems or questions.

Doug

Doug Earl 0 votes
Comment actions Permalink
0
Avatar

Hi Doug!

$NumberOfCurrentGroup seems to be working fine!

Now, I need to get the number of requirements in a specific package which meet certain criteria.  (Actually, the code below seems to be working EXACTLY as I had intended, so I'm including it as a sample for anyone else who is playing around with this.)  How do I use $NumberOf inside a $repeat e.g.,

$repeatPackages where Name startswith 'Functional'

$whenRequirements where TrackingID <= ' '

$Name ($NumberOfRequirements where [TrackingID <= ' '])

$endWhenRequirements

$endRepeatPacakges

Will this give me the number of requirements in each package which are missing TrackingID?

$repeatPackages where Name startswith 'Functional'

$whenRequirements where AssignedTo <= ' ' and IsNested = 'False'

$Name ($NumberOfRequirements where [AssignedTo <= ' ' and IsNested = 'False'])

$endWhenRequirements

$endRepeatPacakges

Will this give me the number of "top level' requirements in any package where there is no assignment?

Tom Tomasovic 0 votes
Comment actions Permalink
0
Avatar

First one small syntactic issue you'll want to fix in both your examples: use <> for not equals instead of <= (!= also works for not equals).

The $NumberOf keyword uses the same context rules as a $list or $repeat (see the reporting user guide for more information about context).  So in your first example, since $NumberOfRequirements is inside a repeatPackages section, it will count only the requirements in the current package being reported on (just as if you had $listRequirements, it would only list the requirements in the current package).

So assuming I'm interpreting your questions correctly, I think the answer to both is yes.  Let me know if you're seeing unexpected results.

Doug

Doug Earl 0 votes
Comment actions Permalink
0
Avatar

Doug,

Actually, my syntax is working as I intended, because, for some reason, some of my fields seem to include a space and others do not.  The <= syntax catches either one, where <> or != will either get the ones which have a space or which do not and, either way, I seem to lose!

While I have your attention, will this syntax (or something similar) work:

$repeatPackages where Name startswith 'Functional' and [Requirements exist where [TrackingID <= ' ']

Thanks for all your help!

Happy Holidays!

Tom

Tom Tomasovic 0 votes
Comment actions Permalink
0
Avatar

Ahh, that explains that.  Actually, I've often thought it would be nice to have an IsEmpty operator instead of having to compare against single quotes.  This is another reason for something like that - it could handle both cases, when the field is completely empty and when it contains all spaces.

Regarding the repeatPackages example, sorry, no that won't work.  The report generator doesn't support combining an "exist" with a "where", nor does it support multiple "wheres" in one line.  I can't come up with any alternative that will work, so I think you'll have to do it in a separate repeat and when statement as you have above.

Doug Earl 0 votes
Comment actions Permalink
0
Avatar

Support Team, I'm attempting to use the $NumberOf keyword to display total # of Packages and then total # of Use Cases within a package...attached is a sample of the file but you'll see the report outputs with a zero value for both. Please let me know how i can update to return the total numbers correctly. thanks!

Esther Turner 0 votes
Comment actions Permalink
0
Avatar

As with any other $list keyword, $numberOf reflects the current context. So, in your sample, the $numberOf keyword is returning firstly the number of packages contained by the current package. If you have no subpackages (within the packages you define with $repeatPackages, which match the same conditions), this explains the 0 on the package heading line. Secondly, with $numberOf inside of the $repeatUseCases loop, it's looking for additional use cases included by the current use case it's reporting each time around, that are also in the same package. Again, if you have no included use cases in the same package, this would explain the 0 there.

I've modified the attached to match up to what I understand as half of your goal: report on the total number of packages matching your set conditions, as well as the number of use cases within a given package. Regrettably however, there isn't a supported method where you can translate that number over into each level and achieve the "package (or use case) 2 of 20" type effect. $Count does of course work, but there isn't a way to store the result of $numberOf in a variable or anything so that you can call that number back in other contexts. Report parameters may work, but it wouldn't be automated and you would potentially need to update your report template each and every time a package or use case was added/removed/moved in your project.

I also removed the "Type = Package" part of your conditional statement at the top. Unless you create a custom field for packages called "Type," that portion is unnecessary. Similarly, “where [Package = $Parent]" was redundant in the use cases section, since by using $numberOfUseCases in the context of a package, it will report the total number of use cases in that package.

Permanently deleted user 0 votes
Comment actions Permalink
0
Avatar

thanks for the feedback, unfortunately i cannot get the result i was looking for i.e. package (or use case) 2 of 20" type effect. Would be great if this were offered in a future release of case complete. thanks for your feedback.

Esther Turner 0 votes
Comment actions Permalink