How can I use ScriptRunner to create multiple subtasks based on a post function?

Jesse Hernandez January 26, 2017

Currently using JIRA CLOUD

I am building a new hire form. Once the form is created and a user clicks "Start Progress" I have it so the issue will automatically create a single subtask and assign it to a user.  

Note: The New Hire form has about 25-30 subtasks that our team will work on simultaneously from ICT to HR and Finance.

  • Create multiple subtasks where I can define subtask summary, assignee and description with a custom script.
  • Send custom email notification if a custom field matches condition
    • Example: If the department matches "Sales" then send an email to "Email Address" with preset message and include issue details(Various custom fields) within the email.

I am new to scriptrunner and groovy and would love a tutorial or guide on where I can find the fields/code needed to make this script work.

 

2 answers

4 votes
Jon Bevan [Adaptavist]
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.
January 26, 2017

Hi Jesse,

You have two options here:

  1. You can create multiple 'Create Subtask' Workflow Post Functions (see http://scriptrunner-docs.connect.adaptavist.com/jiracloud/post-functions.html#_create_subtask) for the 'Start Progress' transition, and also add a Post Function for sending a notification (see http://scriptrunner-docs.connect.adaptavist.com/jiracloud/post-functions.html#_send_notification)
    When you are configuring the 'Create Subtask' post function there is an example code snippet you can use to set the assignee, and its simple to set the description using the following code:

    subtask.fields.description = "Some description"

    For the notification, you can write a code condition that checks the value of a specific custom field:

    def customFieldValue = issue.fields['customfield_10234']
    // We need to return true or false here in the condition code
    return customFieldValue == 'Sales'
  2. Alternatively, you could write a large Script Listener for an Issue Created event that does all of subtask creation manually smile

I hope that helps,

Jon

Jesse Hernandez January 27, 2017

Hello Jon,

Thanks for the prompt answer I appreciate it. For option 1 I know thats possible but due to the fact that we may have 15-30 subtasks I think the manual creation is too tedious and takes too long to edit and modify. I am new to coding but I saw it was possible to setup intellij ide and connect it to JIRA so I can learn the sample groovy code? Can you point me in the right direction for that setup I tried yesterday for 30 minutes but had no clue what I was doing. For option 2 how can I learn to write the code for this, I just need some reference guides and samples!

Jason Huntowski April 11, 2017

Jesse,

 

I am looking for the same information right now. Did you ever find a good way of creating multiple sub-tasks from a single post function script?

I believe when Jon says to create a listener, he is referring to creating a global listener in the add-ons section under Scriptrunner. However, I am not well versed in Groovy and the script to actually fire the "create sub-task" event would probably take me longer to figure out than to just add 15 individual post function scripts.

Anyway, if you have any lessons learned you would like to share, I would love to hear it.

Thanks,

Jason

0 votes
Mervin L. Britoe April 19, 2022

@Jesse Hernandez I know you are specifically referring to Scriptrunner here, but have you considered creating an automation rule using Jira Cloud's native tool called Automation for Jira? It is much less complex than a script being built in Scriptunner

Suggest an answer

Log in or Sign up to answer