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
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());
}
}
}
@Fabio Racobaldo _Catworkx_ Thanks for the code.
Would be possible to block subtask from transitioning if parent task is blocked?
Thanks
Swarna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it is. Please try this code and let me know. For the other we need just to add a line
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Catworkx_
Getting on this line "throw new InvalidInputException("This task is blocked by "+source.getKey());"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add this line on imports :
import com.opensymphony.workflow.InvalidInputException;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what is the relationship between the issues? Linked? Parent-subtask?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.