Assigning an Issue Preserving The User Load

Assigning an Issue Preserving The User Load


Required apps

Availability

This feature is available for Jira server and cloud deployment options.

Problem

Assigning an issue preserving the user load.

Solution

1. Adding a SIL Post Function

We will assume that you already have a project and a workflow associated with it in your Jira installation. If you don't, please refer to Jira documentation on how to do that.

Now create draft for the workflow and go to 'Create' transition.

Let's add a new postfunction. Under the "Post-functions" tab, click "Add" and choose "(k) SILâ„¢ Post-function".


Info

For more information on configuring workflows visit Atlassian

2. Writing the code

After you have added the post function, you are now ready to write the actual code. Immediately after the addition of the post function, you will be presented with our friendly User Interface . Now give your program an appropriate name. This will be used as a base for the name of the file where the program will be saved (See Installation & Configuration for more information).

For assigning the issue preserving the user load, you should write the following code:

string[] prjMembers = projectMembers(project);
string minUser;
number minIssues = -1;
number issuesNumber = -1;
string query = "project = " + project + " AND status in ('Open', 'In Progress', 'Reopened') AND assignee = ";
string jql;
 
for (string user in prjMembers) {
  jql = query + user;
  issuesNumber = arraySize(selectIssues(jql));
  if ((minIssues == -1) || (issuesNumber < minIssues)) {
    minIssues = issuesNumber;
    minUser = user;
  }
}
 
assignee = minUser;

That's it! Click the "Add" button and you're ready to test your program.


Note

It is recommended that you move all SILâ„¢ Post Functions after all other post functions. You can do that by repeatedly clicking "Move Down" until it is at the very bottom of the post functions list.

3. Testing the code

Next, activate your draft workflow by publishing it.

To test the postfunction, create a new issue. Fill the required fields and click "Create" button. The issue will be assigned to the user with the least number of tasks.

4. Assigning issue randomly to project users example

Recently we encountered one case where we needed the issue to be assigned randomly to project users.

For assigning the issue randomly, you should use the random function and write the following code:

string[] prjMembers = projectMembers(project);
number n = arraySize(prjMembers);
 
if (n > 0) {
 assignee = arrayGetElement(prjMembers, random(n));
} else {
 assignee = projectPM(project);
}

See also