How to edit parent ticket description in "Create sub task" script post-function

My goal is creation of some sub tasks in case of issue with issue type = Implementation is created.

I use script runner and it's "Create sub task" post-function - it copies (clones) all necessary fields of parent issue to sub task.

The issue I can't resolve is automatic change of parent issue description. E.g. I'm creating a new ticket and write issue description "Day-to-day contact: John Walter". As soon as the ticket and sub task are created I want to have following parent's issue description:

 

Here is the list of some little tasks which doesn't require separate ticket
Task 1
Task 2
Day-to-day contact: John Walter

I defined following additional sub task actions:

issue.summary = issue.summary + ' Perform initial tuning'
issue.description = 'Please perform initial tuning of a new client.'

So the question is: is there any way to change parent issue description within "Create sub task" script post-function?

1 answer

1 accepted

2 votes

Just use a separate post-function, which should come first:

issue.description = "some long description\netc etc"

Thank you for the answer Jamie . As I understood you mean addition another post function before "Create a sub-task". What kind of post-function should it be? Script post-function -> Define path to own written script? Or probably I avoid creation of new script?

yes, that one. I don't see why you want to avoid another script. Scripts become classes... then they're exactly the same as the class shipped in any other plugin.

I'm not familiar with coding... But looks like following script works (I will use it before "Creates the issue originally." import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.resolution.Resolution import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.event.type.EventDispatchOption //retrieve a specific issue //IssueManager issueManager = ComponentManager.getInstance().getIssueManager() //MutableIssue myIssue = issueManager.getIssueObject("PTTTTTTTT-119") //retrieve current issue (works for workflow post-functions) MutableIssue myIssue = issue //amend the issue description myIssue.description = "[Some text] - " + myIssue.description //If the issue is already created and you change the issue object after that, you have to update the issue manually. Do it with following code //user = componentManager.jiraAuthenticationContext.getLoggedInUser() //issueManager.updateIssue(user, myIssue, EventDispatchOption.DO_NOT_DISPATCH, false) Thank you, Jamie!

I'm trying to put the script on the server but not sure what it should be: a script or a class? When I'm trying to compile either script or class in Intellij IDEA I get following errors: Error:(10, 1) Groovyc: unable to resolve class com.atlassian.jira.event.type.EventDispatchOption Error:(6, 1) Groovyc: unable to resolve class com.atlassian.jira.issue.Issue Error:(9, 1) Groovyc: unable to resolve class com.atlassian.jira.ComponentManager Error:(8, 1) Groovyc: unable to resolve class com.atlassian.jira.issue.IssueManager Error:(7, 1) Groovyc: unable to resolve class com.atlassian.jira.issue.MutableIssue Error:(12, 1) Groovyc: unable to resolve class AbstractIssueEventListener Error:(15, 24) Groovyc: unable to resolve class IssueEvent Could you please advice here?

Don't compile it, just copy the groovy file to the server under your script root and point the post-function to it.

You're right - I've just renamed text file with a script to .groovy and it works now. Unfortunately I met one more issue: sub task description changes as well although I'm specified this strongly in "Create sub task" post function.. *The order of post-functions execution:* 1) Script /opt/atlassian/jira/ChangeImplementationTicketDescription.groovy will be run. 2) Creates the issue originally. 3) Script workflow function : Create a sub-task. Subtask will be created with issue type: Sub-task 4) Fire a Issue Created event that can be processed by the listeners. *The script I'm using:* import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.ComponentManager //retrieve current issue (works for workflow post-functions) MutableIssue issue = issue //amend the issue description issue.description = issue.description + "\n \n" + "some additional information" *Additional issue actions in "Create sub task" post-function:* issue.summary = issue.summary + ' Perform initial tuning' issue.description = 'Please perform initial tuning of the client. \n' + 'Currency sign is *$CURRENCY CODE*' *As a result I have parent ticket with description:* Some specific information some additional information *And description of sub task is:* Please perform initial tuning of the client. Currency sign is *$CURRENCY CODE* some additional information I've tried to move script execution to different positions but nothing changed (although I didn't use issueManager.updateIssue). Could you advice what I'm doing wrong? Probably I should use different class, not MutableIssue? Thank you for your help.

you're probably applying the same workflow to both standard issue types and subtasks. You will need a different workflow for the parent, or better: if (! issue.isSubTask() { ... set description }

This way works perfect: if (! issue.isSubTask()) { ... set description } Thank you again, Jamie

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you