It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner Transition parent issue based on subtask status

Since the original poster of Script Runner Transition parent issue based on subtask status didn't share his script I have to ask the question again.

I would like to automatically transition a parent issue from the status "Backlog Dev" to "Implementation", if one if its subtasks is transitioned to "Implementation". I started of with the script posted at www.petervandevoorde.com/2014/09/18/automatically-transition-a-parent-issue-from-a-subtask-in-jira/ and modified it a little bit. Since

MutableIssue parent = issue.getParentObject();

shows an error, I changed it to

MutableIssue parent = issue.getParentObject() as MutableIssue

The whole script looks like this:

import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
MutableIssue parent = issue.getParentObject() as MutableIssue
 
String originalParentStatus  = parent.getStatus().getSimpleStatus().getName()
def isDevBacklogStatus = originalParentStatus in ['Next Up Dev', 'Backlog Dev', 'Selected for Development']
 
if (isDevBacklogStatus) {
    WorkflowTransitionUtil.setIssue(parent)
    workflowTransitionUtil.setUserkey(currentUser)
    workflowTransitionUtil.setAction(171)
    if (workflowTransitionUtil.validate()) {
        workflowTransitionUtil.progress()
    }        
}

Now the script doesn't show any errors in the edit field, but when triggering the script i get the following error:

2016-02-26 23:28:28,062 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-02-26 23:28:28,093 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: KDEVA-42, actionId: 171, file: <inline script="">
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.workflow.WorkflowTransitionUtil.setIssue() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [KDEVA-24]
 at Script944.run(Script944.groovy:17)

I'm still new to Groovy, so I can't figure out what I need to change to gt it to work. Can someone help, please?

 

6 answers

1 accepted

4 votes
Answer accepted

For me it was failing on: 

String originalParentStatus  = parent.getStatus().getSimpleStatus().getName()

Instead I use:

String originalParentStatus  = parent.status?.name

But the root of your issue is this:

WorkflowTransitionUtil.setIssue(parent)

It should be:

workflowTransitionUtil.setIssue(parent)


correct, sorry I missed this when I posted.

Oh man, "w" instead of "W". Now  feel stupid smile.

Thanks for noticing that. Now the script works.

Hi Flamio,

This can be achieved by placing a custom script transition on the workflow transition to the required status which checks if the issue is a sub-task and if it is in the correct status. Please note you need to place this post function as the bottom last function in the list below the  Fire a Generic Event event that can be processed by the listeners post function.

Below I have attached some sample code for this which shows how when a sub-task is transitioned to In Progress that the parent issue gets transitioned to done.

// Required Imports
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.MutableIssue;

// Only fire if the issue is a Sub Task and in the In Progress Status
if(issue.issueTypeObject.name == 'Sub-task' && issue.getStatusObject()?.name == 'In Progress'){
    // Get the details of the user executing the workflow transition for the issue change history
    String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
    WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

    // Get the ID of the parent issue
    MutableIssue parent = issue.getParentObject() as MutableIssue
    // Update the issue by validating the transition can be completed first before executing it. 
    workflowTransitionUtil.setIssue(parent);
    workflowTransitionUtil.setUserkey(currentUser);
    workflowTransitionUtil.setAction(71); // 71 is the ID of the  Global Done transition on my workflow
    workflowTransitionUtil.validate();
    workflowTransitionUtil.progress();
}

I hope this helps.

Thanks

Kristian

@Kristian Walker (Adaptavist) @Jamie Echlin [Adaptavist] I would like to use this but what if our Sub-task and parent issue type have different workflows? I've tried using this solution but it doesn't seem to work or us. We need to set the status of the parent to In Progress when the Sub-task has been set to In Progress. Our transition ID is the same in both workflows to set the status to In Progress. Would they need to be different in order for this script to work correctly?

Like Leela Kumar Kolla likes this

so you just need a script on the sub-task workflow. You can either hard-code the action ID or look it up by name from the WorkflowManager).

This is super useful and saves us from having to find another add-on! One question, however. In my testing, I get some warnings that indicate that there are deprecation. I'm using JIRA 7.1.4. 

It says:

since 7.0 use Issue.getStatus() instead. @ line 9, column 48
Please use Issue.getIssueType(). Deprecated since v7.0 @ line 9, column 4.
since 7.0 Use Issue.getStatus() instead. @ line 9, column 48. 

When I make the changes I think I need to make, it errors out on me. Can you please provide an updated version of the script with those warnings in mind? I'd like to get them updated so I don't have to touch them again.

 

Otherwise, works like a charm as long as this post-function is AFTER the post function that sets the status to In Progress for the sub-task.

image2016-4-12 14:12:15.png

The deprecation warnings are correct. If you change it as recommended, it should work in JIRA 8 but may not. If you don't change it, it may not work in JIRA 8 but probably will. So, meh.

Changing it as recommended should work fine though, you need to tell us how it errors out.

So, what I'm hearing is, leave it alone until JIRA 8 is closer to a real thing in our world and revisit. I'll do that and revisit the errors later.

 

Thanks!

 

 

The script above worked well for me, as I mentioned in an earlier comment. However, I created a different version of the script to account for a different transition and status (Dev In Progress instead of In Progress) for a different workflow need. All I changed was the ID of the global transition to the one used for Dev In Progress and it's not working. It says 0 failures when it executes, but it doesn't transition the parent. The payload looks correct as well. 

 

{
    "full.module.key": "com.onresolve.jira.groovy.groovyrunnerrungroovy-function (java.lang.String)",
    "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction (java.lang.String)",
    "class.name": "com.onresolve.jira.groovy.GroovyFunctionPlugin (java.lang.String)",
    "issue": "ADEMO-58 (com.atlassian.jira.issue.IssueImpl)",
    "passesCondition": "true (java.lang.Boolean)",
    "transientVars": {
        "changeGroup": "[GenericEntity:ChangeGroup][issue,1399798][author,kim][created,2016-05-06 11:05:15.241][id,5636150] (org.ofbiz.core.entity.GenericValue)",
        "issue": "ADEMO-58 (com.atlassian.jira.issue.IssueImpl)",
        "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@5c681d78",
        "proj": "Project: ADEMO (com.atlassian.jira.project.ProjectImpl)",
        "project": "[GenericEntity:Project][name,Agile Demo][assigneetype,3][description,This is a sample Scrum project for JIRA Agile.\r\n<br><br>\r\nSample Sprint 1 started 21 days 10 hours 20 minutes ago ends 7 days 10 hours 20 minutes ago completed 7 days 11 hours 40 minutes ago\r\n<br><br>\r\nSample Sprint 2 started 7 days 9 hours 10 minutes ago ends 6 days 15 hours 10 minutes \r\n<br><br>][projecttype,software][id,22706][counter,59][avatar,10011][originalkey,ADEMO][url,null][lead,kim][key,ADEMO] (org.ofbiz.core.entity.GenericValue)",
        "currentSteps": "[SimpleStep@10[owner=, actionId=91, status=null]] (java.util.ArrayList)",
        "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@202ef008",
        "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@7d427c6a",
        "userKey": "kim (java.lang.String)",
        "originalAssigneeId": "null (org.codehaus.groovy.runtime.NullObject)",
        "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@65d31e8f",
        "oldStatus": "com.atlassian.jira.issue.status.StatusImpl@fffca195",
        "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@1e40e426",
        "createdStep": "SimpleStep@10[owner=, actionId=0, status=null] (com.opensymphony.workflow.spi.SimpleStep)",
        "originalissueobject": "ADEMO-58 (com.atlassian.jira.issue.IssueImpl)",
        "actionId": "91 (java.lang.Integer)",
        "pkey": "ADEMO (java.lang.String)",
        "changeItems": "[com.atlassian.jira.issue.history.ChangeItemBean@26770eee[fieldType=custom,field=In Progress Date,from=2016-05-06T10:54:43-0500,fromString=05/06/2016 10:54 AM,to=2016-05-06T11:05:15-0500,toString=05/06/2016 11:05 AM,created=<null>], com.atlassian.jira.issue.history.ChangeItemBean@48388766[fieldType=jira,field=status,from=10048,fromString=Dev In Progress,to=10048,toString=Dev In Progress,created=<null>]] (java.util.LinkedList)"
    },
    "log": "org.apache.log4j.Logger@2c467a85"
}

Check the logs for the reasons why it didn't fail. Expected errors, eg permissions errors, won't show as failures.

On the Execution Information screen, the logs say:

Time (on server): Mon May 09 2016 10:24:44 GMT-0500 (Central Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

No logs were found for this execution.


I don't have any logging statements in my script. I'm not having the best luck getting them added. Can you tell me what I would need to add to this script to make it work to gather logs that would be helpful?

 

// Required Imports
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.MutableIssue;

// Only fire if the issue is a Sub Task and in the In Progress Status
if((issue.issueTypeObject.name == 'Sub-task' || issue.issueTypeObject.name == 'Technical task') && issue.getStatusObject()?.name == 'In Progress'){
// Get the details of the user executing the workflow transition for the issue change history
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

// Get the ID of the parent issue
MutableIssue parent = issue.getParentObject() as MutableIssue
// Update the issue by validating the transition can be completed first before executing it.
workflowTransitionUtil.setIssue(parent);
workflowTransitionUtil.setUserkey(currentUser);
workflowTransitionUtil.setAction(91); // 91 is the ID of the Global Dev In Progress transition
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();
}

you're better off using the "fast-track" built-in script. It's tricky doing a transition within another transition. If you refresh the issue does it work? How about change it then refresh?

Refreshing doesn't change anything.

 

I looked at the Fast Track option, but it's only pertaining to the issue being transitioned, isn't it? So, if what I'm trying to do is transition the parent of a subtask to "Dev In Progress" when one of the sub-tasks moved to "Dev In Progress" this won't work, will it? It's strange that this seems to be working for the generic "In Progress" transition but not for "Dev In Progress."

oh ok I missed that. Should be fine then. Check the output from .validate() and .progress, eg:

log.warn workflowTransitionUtil.validate()
log.warn workflowTransitionUtil.progress()

then check the log output.

I tried both log.warn and log.info and there's nothing in the logs. I can see where I updated the workflow but nothing is in the logs either on the Execution Information or in atlassian-jira.log after running the operation.

Any thoughts on how to get some more logs out of this? I can open a support ticket if that's better, but I know that the support site guided me to Answers.

Hi Kim,

I would raise a request through the Adaptavist support portal in order to get the developers to investigate this further.

Thanks

Kristian

Sorry Kim, you are in the right place for support here... this is not covered in our support remit. We will get to this question.

If you use this:

log.warn "Validate: " + workflowTransitionUtil.validate()
log.warn "Progress: " + workflowTransitionUtil.progress()

do you at least see those lines?

Sorry, that was definitely my fault. This line: 

if((issue.issueTypeObject.name == 'Sub-task' || issue.issueTypeObject.name == 'Technical task') && issue.getStatusObject()?.name == 'In Progress'){

 

Was still looking for "In Progress" and not "Dev In Progress". So sorry!

Kristian, Can you help me?

I need to update the parent Date/time field with current timestamp when a child task is done.

 

Need: Aging charts , like To track how long it took for testing to being after coding task is done, etc

 

The question is posted here. you can provide answer there.

https://community.atlassian.com/t5/Questions/How-to-update-a-parent-field-when-subtsk-state-changes/...

Hello,

I know this is an old thread but I was hoping someone could help me. I have used this script to successfully transition a parent issue to a particular status when a subtask is transitioned to closed. I added a condition to my Parent issue work flow to prevent this task from being completed until all subtasks are complete. I was able to get the parent transition to work with a single subtask.. or when a parent has multiple subtasks, as soon as one is transitioned to complete the Parent is also. I added the Subtast blocker condition to prevent the parent from being closed untill all subtasks are closed. Now when I try to move a subtask to complete I get this error message:

org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.

It seems that you have tried to perform an illegal workflow operation.

If you think this message is wrong, please contact your Jira administrators.

 I have done an internet search for this error and tried to make the parent transition a global transition based on the my search findings but that has not fixed my issue.

Has anyone encountered this? Any idea what I could do to fix this?

And help is greatly appreciated.

Thanks!

-Curtis

@Curtis Freudigmann @Luke McDonald @Jamie Echlin [Adaptavist] 

Can someone help me on the below scenario, am new to Groovy.

Question - How do I automatically change a status change on a parent issue based on the status of its linked issue statuses when a linked issue status is CLOSED?

 

We have Release Workflow once the Release issue type is progressed to "QA Deployment" then the QA: Scheduled_Deployment task will auto create.

And the Release issue type is progressed to "Deploy" then Prod: Scheduled_Deployment task will auto create.

Now the Requirement is - Once the QA: Scheduled_Deployment task closed then the Release issue type status update as "UAT"

Once the Prod: Scheduled_Deployment task closed then the Release issue type status update as "PRODUCTION"

 

- We are using Script Runner for JIRA v5.2.1 and JIRA Server v7.3.6

Please help me with a sample script to achieve this...

Thanks! Just set this up in our system. Still looks good...   Clean code is:  

"import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.comments.CommentManager;
import com.opensymphony.workflow.WorkflowContext;
import org.apache.log4j.Category;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
MutableIssue parent = issue.getParentObject() as MutableIssue

String originalParentStatus = parent.getStatus().getSimpleStatus().getName()
def isDevBacklogStatus = originalParentStatus in ['Open']

if (isDevBacklogStatus) {
workflowTransitionUtil.setIssue(parent)
workflowTransitionUtil.setUserkey(currentUser)
workflowTransitionUtil.setAction(11)
if (workflowTransitionUtil.validate()) {
workflowTransitionUtil.progress()
}
}

"

Luke, Can you help me?

I need to update the parent Date/time field with current timestamp when a child task is done.

 

Need: Aging charts , like To track how long it took for testing to being after coding task is done, etc

 

The question is posted here. you can provide answer there.

https://community.atlassian.com/t5/Questions/How-to-update-a-parent-field-when-subtsk-state-changes/...

Try changing 

MutableIssue parent = issue.getParentObject() as MutableIssue

to

def parent = ComponentAccessor.getIssueManager().getIssueObject(issue.getParentId())

Unfortunately I still get the same error

2016-03-01 22:46:11,997 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-03-01 22:46:11,998 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: KDEVA-30, actionId: 171, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.workflow.WorkflowTransitionUtil.setIssue() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [KDEVA-16]
	at Script997.run(Script997.groovy:17)

Line 17 is

WorkflowTransitionUtil.setIssue(parent)

Boris, Can you help me?

I need to update the parent Date/time field with current timestamp when a child task is done.

 

Need: Aging charts , like To track how long it took for testing to being after coding task is done, etc

 

The question is posted here. you can provide answer there.

https://community.atlassian.com/t5/Questions/How-to-update-a-parent-field-when-subtsk-state-changes/...

WorkflowTransitionUtil.setIssue(parent)

should be

workflowTransitionUtil.setIssue(parent)

ie a small w.

0 votes

@Josh Costella 

Here is the Script man, I have the same task, I modified little based on my project workflow, now it is working fine to me.

// Required Imports
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;

// Only fire if the issue is a Sub Task and in the In Progress Status
if(issue.issueTypeObject.name == 'Sub-task' && issue.getStatus()?.name == 'In Progress'){
// Get the details of the user executing the workflow transition for the issue change history
//String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
String userKey = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);

// Get the ID of the parent issue
def parent = (MutableIssue) issue.getParentObject()

// MutableIssue issueparent = issue.getParentObject() as MutableIssue

//def issueparent = ComponentAccessor.getIssueManager().getIssueObject(issue.getParentId())

String originalParentStatus = parent.getStatus().getSimpleStatus().getName()

def isStatus = originalParentStatus in ['To Do']

if(isStatus)
{
// Update the issue by validating the transition can be completed first before executing it.
workflowTransitionUtil.setIssue(parent);
workflowTransitionUtil.setUserkey(userKey);
workflowTransitionUtil.setAction(101); // 101 is the ID of the Global In Progress transition on my workflow
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();

}


}

Hello,

Since release 8.x, JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class) is deprecated. I tried to use JiraUtils.loadComponent("workflowTransitionUtil", WorkflowTransitionUtilFactoryImpl.class ) where workflowTransitionUtil is the Class Name. But I get this error:  java.lang.ClassNotFoundException: workflowTransitionUtil

Any idea which Class Name I should use ?

Thanks

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,347 views 8 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you