How to count user's issues?

In a state machine workflow, when the ticket enter the "Pending tests" status, I want to assign the ticket to a member of "QA Testers".
To do so, I want to find the tester with less assigned issues and the assign the ticket to him.

I'm a bit stuck, as I can't find the right code for that.

So far, this is what I've accomplished:
state Pending testing { 
  enter { 
    var testers = {group: QA Testers}; 
    var tester_users = testers.getUsers(); 
    var issues_count = 1000; 
    for each tester_user in tester_users { 
      var user_issues = tester_user.getIssues(Everything, "State: {Pending testing}"); 
      user_issues.????????; 
    } 
  } 
    
  on test failed[always] do {<define statements>} transit to Testing failed 
    
  on test need improvements[always] do {<define statements>} transit to Testing need improvement 
    
  on test passed[always] do {<define statements>} transit to Testing passed 
}
prettyPrint();
Actually, this wouldn't work even if user_issues would have a "count" property, because all the logic to fine the user with less issues is missing.
I was thinking to store everything in an associative array, sort that array and get the result there, but the workflow language doesn't seem to know what an simple array is (let alone associative arrays and array sorting...).

So, any advice on how I can proceed?
3 comments
Comment actions Permalink
Hi Andrea,

First of all, size function is not implemented for arrays now, unfortunately. It's disgusting, I know, but it's not a show-stopper, there is a workaround. Creating mutable collections id also not allowed.

However, to get the user with the least number of issues, you actually need only two values to store while iterating over testers - the minimum number of issues assigned among the users already checked and the corresponding user.

Thus, you should add the following code:
Before the for loop:
...
var less_busy_user = tester_users.first; // initializing the var before the loop
var issues_count_min = 1000; // or other number you find big enough
prettyPrint();
Then, inside the for loop body, after getting user_issues:
...
var size = 0;
for each user_issue in user_issues {
  size = size + 1;  // workaround to get number of issues in this array
}
if size < issues_count_min {
  issues_count_min = size;     // we've found the tester with less issues assigned
  less_busy_user = tester_user;
}
prettyPrint();
And at the very end, after all this staff:
issue.Assignee = less_busy_user;
prettyPrint();
Hope that helps.
0
Comment actions Permalink
Thank you Mariya,

Your suggestion makes sense to me, though a bit overcomplicated, because of the lack of size functions and collections.

I've already implemented it, but I can't test it right now.

But again, it really makes sense, so I would consider it as resolved.

Thanks again!
0
Comment actions Permalink
You are welcome, Andrea!

I'm sorry again for this overcomplication, we are still working on improving our workflow.

I will be glad if you let us know if this solutions works for you, as you get an opportunity to test it.
0

Please sign in to leave a comment.