Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to block Task B to close till Task A is not closed

Swarna Radha
Contributor
October 30, 2018

Hi,

I want to block Task B from closing till Task A is not closed. How to achieve this using validator script runner?

 

Thanks

Swarna

3 answers

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

Hi @Swarna Radha,

 

please try this code for your validator :

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.Issue;


IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
List<IssueLink> issueLinks = issueLinkManager.getInwardLinks(issue.getId());
for(IssueLink il : issueLinks){
if(il.getIssueLinkType().getName().equals("is blocked by")){
Issue source = il.getSourceObject();
if(!source.getStatusObject().getName().equals("Closed")){
throw new InvalidInputException("This task is blocked by "+source.getKey());
}
}
}
Swarna Radha
Contributor
October 30, 2018

@Fabio Racobaldo _Catworkx_ Thanks for the code.

Would be possible to block subtask from transitioning if parent task is blocked?

Thanks

Swarna

Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

Yes, it is. Please try this code and let me know. For the other we need just to add a line

Swarna Radha
Contributor
October 30, 2018

Hi @Fabio Racobaldo _Catworkx_

Getting on this line "throw new InvalidInputException("This task is blocked by "+source.getKey());"

Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

add this line on imports :

 

import com.opensymphony.workflow.InvalidInputException;

Swarna Radha
Contributor
October 30, 2018

@Fabio Racobaldo _Catworkx_, I have updated the code below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.Issue;
import com.opensymphony.workflow.InvalidInputException

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
List<IssueLink> issueLinks = issueLinkManager.getInwardLinks(issue.getId());
for(IssueLink il : issueLinks){
if(il.getIssueLinkType().getName().equals("blocks")){
Issue source = il.getSourceObject();
if(!source.getStatus().getName().equals("Closed")){
throw new InvalidInputException("This task is blocked by "+source.getKey());
}
}
}

But both issues are blocked instead of one.

Please see screenshots.

Task QA.pngTask SIT.png

Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

Hi @Swarna Radha,

 

this code should be used as a validator. If you don't see the transition, probably, you have some condition that block user to see that transition.

Swarna Radha
Contributor
October 30, 2018

@Fabio Racobaldo _Catworkx_ I have only these conditions (Only the assignee of the issue can execute this transition.
Add grouped condition Edit Delete Only users in group jira-administrators can execute this transition.
Add grouped condition Edit Delete Only users in project role Appli Sup and Dev Team Lead can execute this transition.
Add grouped condition Edit Delete Only users in project role IT Services Team Lead can execute this transition.)

I am JIRA admin  and the code has not run when i test it

Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

If you don't see the button it means that some condition is blocking you. Validator will be excetued aftter that you click the transition button so I can't help on that. Please verify that all your condition are in OR.

0 votes
Fabio Racobaldo _Catworkx_
Community Champion
October 30, 2018

Hi @Swarna Radha,

 

are those task linked each others? If yes, your validator should retrieve link and the related task associated. After doing that you need to check the status of Task A and, based on that, define if task B can be closed.

Do you need the code?

Swarna Radha
Contributor
October 30, 2018

Hi,

Both tasks are  linked "is blocked by". 

If possible can you please send me the code?

 

Another issue: If task is blocked that is it cannot transition. Can their subtasks be blocked also?

Thanks

Swarna

0 votes
Tom Lister
Community Champion
October 30, 2018

Hi @Swarna Radha

what is the relationship between the issues? Linked? Parent-subtask?

Suggest an answer

Log in or Sign up to answer