Can we prevent transition of subtask based on linked (subtask)issue status in jira?
We have button on subtask to change transition but I want to put validation here.
Prevent transition if linked issues are not yet approved.
Is it possible?
Sure you can create complex validations.
Take a look at the free plugin https://marketplace.atlassian.com/apps/575829/workflow-enhancer-for-jira. There you'll find a lot of conditions to use in your workflows.
You might need to use some sort of calculated field, or my prefered option a SIL custom field, to calculate something those conditions themselves can't calculate and then use that value to trigger the condition or not.
If you haven't come across SIL custom fields yet, they come with https://marketplace.atlassian.com/apps/1210749/power-custom-fields-for-jira. I believe you don'e need to purchase the license just to use the SIL custom fields, at least up until some version, but if you think you're going to make extensive use of this it would be adviseable to unlock the full potential of the pugin. In any case check it out.
Hope it helps
Actually, We have two workflows.
1. Approvals workflow : In the post function of approval's workflow what we have implemented, when we approve all the approval subtasks then the status of ITRequest(linked to approval subtasks) will be automatically changed to "scheduled" state.
2. ITPS workflow : But when we manually click on the Schedule button on "ITRequest" subtask, then it's state changed to "schedule". So I need to put validation here : should not change to "scheduled" state until and unless all the approvals sub task got approved.
So What kind of validation we need to implement here.
Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have just described the validation you need!
Go ahead and try the plugins I've talked you about.
From the top of my head I would use a SIL custom field to check if the number of subtasks of a given issue is equal to the number of APROVED subtasks of the issue. You could then use that field as the condition to enable or even execute the transitions you describe.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you are right.
I have implemented this as you said but I have one doubt.
Please see my code below:
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Category
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.opensymphony.workflow.WorkflowContext;
def Category log = Category.getInstance("com.innovalog.jmwe.plugins.functions.CommentIssueFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "Scheduled Condition"
log.info("started Condition");
def approvalIssuesCount = 0;
def approvedStatusCount = 0;
MutableIssue parentIssue = issue as MutableIssue
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
MutableIssue linkedIssue = issueLink.getSourceObject() as MutableIssue
String type = linkedIssue.getIssueType().getName();
log.info("linkedIssue" + linkedIssue);
if(type.equals("Approval"))
{
approvalIssuesCount++;
String linkedIssueStatus = linkedIssue.getStatus().getName();
if(linkedIssueStatus.equals("Approved"))
{
approvedStatusCount++;
}
log.info("linked issues Approval Status******************* : " + linkedIssueStatus);
}
}
log.info("approvalIssuesCount : " + approvalIssuesCount);
log.info("approvedStatusCount : " + approvedStatusCount);
if(approvalIssuesCount != approvedStatusCount )
{
// what I need to write here
}
if(approvalIssuesCount == approvedStatusCount )
{
// what I need to write here
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm going to assume all that is for the SIL custom field.
I didn't even know that custom field had such capabilities since I never needed a field half that complicated but I'm happy to see that you have achieved your goal.
All you need to do now is the final step, wich is set the value we're going to later use as a condition in the workflow.
There are 2 possible cases:
1. Best case scenario. You simply set return = whatever. for example FALSE / TRUE. and you can then edit the postfunction in the workflow and read directly that SIL field.
2. You can't select the SIL field when you want to edit the postfinction in the workflow. In this case instead of using return, you'll need to write your FALSE / TRUE value in some other auxiliar custom field. So... you'll have to do if whatever... cf_00000= FALSE / TRUE and use that cf value as a validator for the transition.
I hope I've understood you proprerly and also that I made myself clear enough.
In any case I can see you really know your stuff so I'm confident we'll sort things out in no time if there is any missundesrtanding :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply.
I have added : return false, but it does not work.
State is changing to scheduled yet.
added validation using 'custom script condition' and 'custom script validation' but it does not work.
Please see my code:
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Category
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.opensymphony.workflow.WorkflowContext;
def Category log = Category.getInstance("com.innovalog.jmwe.plugins.functions.CommentIssueFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "Scheduled Condition"
log.info("started Condition");
def result = true;
def approvalIssuesCount = 0;
def approvedStatusCount = 0;
MutableIssue parentIssue = issue as MutableIssue
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
MutableIssue linkedIssue = issueLink.getSourceObject() as MutableIssue
String type = linkedIssue.getIssueType().getName();
log.info("linkedIssue" + linkedIssue);
if(type.equals("Approval"))
{
approvalIssuesCount++;
String linkedIssueStatus = linkedIssue.getStatus().getName();
if(linkedIssueStatus.equals("Approved"))
{
approvedStatusCount++;
}
log.info("linked issues Approval Status******************* : " + linkedIssueStatus);
}
}
log.info("approvalIssuesCount : " + approvalIssuesCount);
log.info("approvedStatusCount : " + approvedStatusCount);
if(approvalIssuesCount != approvedStatusCount )
{
result = false;
}
return result;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Troubleshooting time :)
You keep pasting your code but you haven't mentioned any errors shown and that worries me because the SIL custom field editor normally shows an error in the line where something has happened. Are you sure you're using this type of field? Because maybe it doesn't support some of those expressions.
The following is an example to get every linked issue of a given type
https://confluence.cprime.io/display/TR/JQL+-+Return+All+Issues+Linked+to+Issue+for+Given+Link+Type
As you see, it seems way more simple than your example.
After making sure we're talking about the same thing here... What I would do:
- Check with a test issue if the field is returning the expected values for the number os linked issues and number of aproved linked issues.
- Check the transition validation. If you could provide a screen capture to see what condition are you using it would be great.
- If the returned result is as expected and the validation expression is correct maybe you need to use an auxiliar custom field as I've told you before because it might not be working directly with the SIL field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for the CONDITION (not validation, sorry...) I was initially thinking of using a UNIVERSAL CONDITION. And the expression to check would be simply "your_custom_field = FALSE" or "your_custom_field = TRUE"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Buddy,
Actually I was implementing the code inside 'custom script validator' and it was not working.
But now I have put my code inside the 'simple scripted validator' and its working fine.
Thanku very much @Iago Docando
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nice :)
Please accept the answer so it can be of help to others in the future.
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.