I’ve been trying to do some advanced JIRA configuration recently, with mixed success.
The requirement was to have issues in a project which could be viewed only by a specific user (not necessarily the assignee).
I discovered that “Issue Security Schemes” can have levels which allow access based on a “User Custom Field Value”. Fantastic. I added a custom field, let’s call it “Employee”, and added it to an Issue Security Level. Applied to the project and bingo, users can only see issues where they have been entered into the “Employee” field.
Too easy. I added a subtask to an issue where I was the employee. No error message, but no subtask appeared either.
My understanding was that you could not set issue security on subtasks, because they inherit the issue security of the parent. I assumed the intention of this was that if you could see an issue, you should be able to see its children. But no – they specifically inherit the issue security setting from the parent, rather than its visibility – as confirmed in Atlassian Answers. So because the sub-task does not have an “Employee” field, I can’t see it. Bother.
Of course, I could use a workflow post-function so that when subtasks are created, the employee field is set to that of the parent. But what if the value is changed in the parent? It’s a nuisance to have to change all the sub-tasks too.
Time to investigate the Script Runner plugin.
Here’s the code for my Scripted field, which gets the value of the Employee field in the parent issue.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.fields.CustomField def componentManager = ComponentManager.getInstance() def parentIssue = issue.getParentObject(); CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager() CustomField customField = cfManager.getCustomFieldObject(99999) parentIssue.getCustomFieldValue(customField)
It is almost too easy. I think it may be the answer to some of the other requests I’ve had for custom fields in JIRA, but unfortunately it doesn’t solve this problem. The calculated value appears perfectly on the page when viewing a sub-task. But, when I go to the “Issue Security Level” and click in the “User Custom Field Value” drop down, it doesn’t appear! It’s configured with the “User Picker” Searcher and template, so I don’t think there’s much more I can do.
Back to the drawing board…