Script Runner Transition parent issue based on subtask status

flaimo March 1, 2016

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?

 

8 answers

1 accepted

4 votes
Answer accepted
Cristina_Abunei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2016

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)


JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2016

correct, sorry I missed this when I posted.

flaimo March 2, 2016

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

Thanks for noticing that. Now the script works.

2 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2016

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

Josh Costella April 7, 2016

@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
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2016

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).

Kim Wall April 12, 2016

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 12, 2016

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.

Kim Wall April 13, 2016

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!

 

 

Kim Wall May 6, 2016

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"
}
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2016

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

Kim Wall May 9, 2016

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();
}
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2016

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?

Kim Wall May 9, 2016

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."

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2016

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.

Kim Wall May 9, 2016

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.

Kim Wall June 7, 2016

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.

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2016

Hi Kim,

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

Thanks

Kristian

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2016

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 8, 2016

If you use this:

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

do you at least see those lines?

Kim Wall June 9, 2016

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!

Ratna Kumar Lekkala September 14, 2017

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/...

Curtis Freudigmann February 21, 2019

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

Prasad Andrews March 22, 2019

@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...

1 vote
Luke McDonald September 11, 2017

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()
}
}

"

Ratna Kumar Lekkala September 14, 2017

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/...

0 votes
Lars Swart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2021

Hi Laurie,

the difference between your code and mine is the condition.

 

You wrote

issue.getIssueTypeObject().id == '13200' && issue.getStatusObject() == 'Start Testing')

 

I wrote

issue.getIssueType().id == '10003' && issue.summary == 'Create User')

 

 

So my first try would be to change the function for looking up the id.

I slightly remember, that I also tried getIssueTypeObject but I don't know why I didn't used it in the end.

 

Then try the issue.summary aswell. If that works, the issue.getStatusObject() seems to be your problem.

 

Lars

0 votes
Lars Swart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2021

Hi, I have solutions for the people that are searching working scripts in 2021.

 

1) If you want transition the parent issue when a specific subtask (Create User) is closed use this script as a Script Post-Function [ Scriptrunner ] → Custom script post-function 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.MutableIssue

Integer actionId = 21 // The transition ID

MutableIssue parent = issue.getParentObject() as MutableIssue
IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
TransitionOptions transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

IssueService.TransitionValidationResult result = issueService.validateTransition(currentUser,
parent.getId(),
actionId,
issueService.newIssueInputParameters(),
transitionOptions)

//Checks if the result is valid, the Issue Type is 'Sub-task' and the Summary is "Create User". Do ensure that the Issue Type name matches.
if (result.isValid() && issue.getIssueType().id == '10003' && issue.summary == 'Create User') {
issueService.transition(currentUser, result)
} else {
log.warn result.getErrorCollection().getErrors()
}

 

2) If you want to transition a parent issue when all subtasks are resolved, but this should only be happening, when the parent is in a specifice status (status 2).

 

You need a Script Post-Function [ Scriptrunner ] → Transition parent when all subtasks are resolved

 

and use this code as condition.

// Required Imports
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.issue.MutableIssue;

// Get parent
MutableIssue parent = issue.getParentObject() as MutableIssue

// Get status name of parent
String originalParentStatus = parent.status?.name

// Compare status name of parent
originalParentStatus == 'Status 2'

 

Hopper May 4, 2021

Note that setting the Transition parent when all subtasks are resolved does not work  if the parent's target transition implements the condition "Hide transition from user". ScriptRunner's build in script does not set skipPermissions in the transition options.

LaurieC May 28, 2021

@Lars Swart 

I've tried to use the code to update the parent status when the subtask is a Test Step (id= 13200) and it's status is "Start Testing" 

It says it is working, but it isn't transitioning the parent when I start the subtask. Here's what I have. Does anything stand out to you?

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.MutableIssue

Integer actionId = 11 // The Testing transition ID

MutableIssue parent = issue.getParentObject() as MutableIssue
IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
TransitionOptions transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

IssueService.TransitionValidationResult result = issueService.validateTransition(currentUser,
parent.getId(),
actionId,
issueService.newIssueInputParameters(),
transitionOptions)

//Checks if the result is valid, the Issue Type is 'Test STep' and the Status is "Start Testing". Do ensure that the Issue Type name matches.
if (result.isValid() && issue.getIssueTypeObject().id == '13200' && issue.getStatusObject() == 'Start Testing') {
issueService.transition(currentUser, result)
} else {
log.warn result.getErrorCollection().getErrors()

Thanks for posting the final code!
Laurie

0 votes
Leela Kumar Kolla August 21, 2019

@[deleted] 

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();

}


}

Cedric Delavy September 24, 2019

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

Lars Swart
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 18, 2021

Hi @Cedric Delavy 

did you find a working script that you can share?

 

Lars

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2016

WorkflowTransitionUtil.setIssue(parent)

should be

workflowTransitionUtil.setIssue(parent)

ie a small w.

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2016

Try changing 

MutableIssue parent = issue.getParentObject() as MutableIssue

to

def parent = ComponentAccessor.getIssueManager().getIssueObject(issue.getParentId())
flaimo March 1, 2016

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)
Ratna Kumar Lekkala September 14, 2017

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/...

Suggest an answer

Log in or Sign up to answer