Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Limit creation of SubTask with script runner (based on parentIssue)

xion_admin July 3, 2015

Hi I want to allow creation of sub task only for the assigned user.

I use a validator condition in the create transition of the sub task.

For the validator I use script runner example script.

import com.atlassian.jira.component.ComponentAccessor
parentIssue = ComponentAccessor.issueManager.getIssueObject(webwork.action.ActionContext.getRequest().getParameter("parentIssueId") as long)

return currentUser == parentIssue.assignee

 

But for unknown reason It doesnt work.

Any hint, how to fix this?

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2015

If you're using "simple scripted validator" the condition should be:

! issue.isSubTask() || issue.reporterId == issue.parentObject.assignee?.name
xion_admin July 5, 2015

Shouldn't it be?: issue.isSubTask() && issue.reporterId == issue.parentObject.assignee?.name One additional question: I thought I cannot use the issue object, because the issue itself is not yet created. The validator is used in the create step of the issue. That's why I use the approach with "ComponentAccessor.issueManager".

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2015

> Shouldn't it be?: My way works when the workflow is the same for the parent as the subtask. Yours will fail if it's not a subtask. If you have a separate workflow for the subtask you don't need the first bit at all. > I thought I cannot use the issue object, because the issue itself is not yet created. The validator is used in the create step of the issue. That's why I use the approach with "ComponentAccessor.issueManager" I would have said the same, but I tested this on jira 6.4.x on the Create step and it worked as expected, which I was a bit surprised about.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2015

Also your approach of using ActionContext will fail in a bad way if the issue is created via REST, as in that case it will be null, so if you use that you need to guard against it being null.

TAGS
AUG Leaders

Atlassian Community Events