Hi,
I am using the script below to do the transition to "Open" when all linked issues are closed.
After execution, main ticket remains to escalated to supplier instead to Open.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
import org.apache.log4j.Category
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.MutableIssue
log.setLevel(org.apache.log4j.Level.DEBUG)
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
log.debug "Original: ${issue.getId()}, ${issue.getKey()}. DETECTED " + issue.getStatus().name
List<IssueLink> allInIssueLink = issueLinkManager.getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
def linkedIssue = issueLink.getDestinationObject();
log.debug "linked: ${linkedIssue.getId()}, ${linkedIssue.getKey()}. DETECTED " + linkedIssue.getStatus().name
if (linkedIssue.getStatus().name.equals("Open")) { // STATO della issue collegata
log.debug "linked Content: ${linkedIssue.getId()}, ${linkedIssue.getKey()}."
//We can transition the parent ticket
log.debug "start transition"
workflowTransitionUtil.setIssue((MutableIssue) linkedIssue);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction (221); //Transition ID
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
log.debug "end transition"
}
}
Kindly advice.
Thanks,
Swarna
ok, so I'm not sure this script will get you what you want with minor fixes.
Looking at your current script
issueLinkManager.getInwardLinks(issue.getId());
returns only the original issue in the list, not the issue it's liked to.
I'm not sure how issue links are defined on your instance so you might be able to fix this by using
Check the documentation on https://docs.atlassian.com/software/jira/docs/api/7.1.7/com/atlassian/jira/issue/link/IssueLinkManager.html#getInwardLinks-java.lang.Long- vs https://docs.atlassian.com/software/jira/docs/api/7.1.7/com/atlassian/jira/issue/link/IssueLinkManager.html#getOutwardLinks-java.lang.Long-
issueLinkManager.getOutwardLinks(issue.getId());
And if you have only 1 issue linked to it you should get the parent/central one you would like to modify.
However this is not enough as you might have a parent issue with more than one linked issue and this would work only if you had 1 linked issue.
The script needs to be modified to:
1. find the "parent" issue linked with the one that was transitioned
2. get all the linked issued of the parent and check they are all closed
3. execute the query for the issue you want.
Currently
1. is not working because you're getting the same original issue
2. "parent" level checks are not present in the script.
3. should work.
Hope this helps you on the right path.
Cheers,
Radu
Can you provide me the script. Am not doing at scripting :(
Thanks
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 ,
Sounds a bit complicated, why don't you use automation and configure the automated transition of the parent ticket once all linked tickets reached a "Done" state.
Let me know if this works for you.
Cheers,
Radu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have used automation rule before scripting, it does not check if all linked issues are closed. If One linked issue is closed, issue is transitioned to Open. But all the remaining linked issues are still opened
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 ,
Looking through the code I see:
...
if (linkedIssue.getStatus().name.equals("Open")) {
...
I understand that means "If the linked issue is in status Open then" do the transition 221.
I think you could remove the condition if you want to transition all the issues through transition 221
Cheers,
Radu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Radu,
I have removed the condition. When I run the script. In the log it said the following:
2019-08-22 08:28:28,375 DEBUG [workflow.ScriptWorkflowFunction]: Original: 148363, CM-222. DETECTED Closed 2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: linked: 148363, CM-222. DETECTED Closed 2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: linked Content: 148363, CM-222. 2019-08-22 08:28:28,376 DEBUG [workflow.ScriptWorkflowFunction]: start transition 2019-08-22 08:28:28,380 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-08-22 08:28:28,381 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CM-222, actionId: 11, file: <inline script> java.lang.IllegalArgumentException: No workflow action with id '221' available for issue CM-222
I have added the script in the linked issue in the closed transition. When it closes, it transitions the main ticket
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
If the issue is CM-222 how can the linked issue be also CM-222 ?
I'd try to run it on my instance. Are you using Script Runner for this?
Thanks,
Radu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CM- 222 is linked to main ticket.
My scenario is that when agent clicks on escalated to supplier, a linked issue is created ( Supplier Task). When all supplier tasks are closed, the main ticket should transition from escalated to supplier to "Open".
I have added the code on close transition of the supplier task.
workflowTransitionUtil.setAction (221); //Transition ID- this is the transition of the main ticket from escalated to supplier to open.
I am using script runner.
Thanks,
Swarna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.