Only Create a Sub-task for a Specific Custom Field Value

Shawna Morris March 30, 2020

I've created a Script Post-Function [ScriptRunner] Function that automatically creates Sub-tasks when a New issue is created in the project. 

Now, I want to apply a condition that will only create those Sub-tasks when a specific custom field is set to a specific value, i.e., Project Type (Custom Field) == Project Initiative (dropdown menu option). 

Any help would be greatly appreciated! 

2 answers

0 votes
Jeff Tillett
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 2, 2024

Did you ever find a solution for this? I am trying to do this now, used a built in code snippet, created an issue where I KNOW it will return true, but it's still not creating the task.

This is my current code (no errors in either the editor or the execution): 


cfValues['cf[38901]'] == "developer"
0 votes
Taylor Huston March 31, 2020

Can you share your script as it currently is with us?

Shawna Morris March 31, 2020

Condition: Which is where I'm wanting to put only Project Type (Custom Field) = "Project Initiative". 

Target Issue Type: Sub-task

Subtask Summary: PM Activities - Define/Design

Code:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor

issue.setDescription("For Project Managers to track and report their time against this Initiative. Please make sure to update the 'Original Estimate' field under the 'Time Tracking' tab to acurately estimate the time you'll spend supporting this Initiative.")

MutableIssue myIssue = issue
Project project = myIssue.getProjectObject()

def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'PMO - PMs')

if (theComponent == null) {
theComponent = ComponentAccessor.getProjectComponentManager().create("PMO - PMs","","",0,project.getId())
}

myIssue.setComponent([theComponent])

// set Original Estimate to 10d
issue.setEstimate((Long) 288000)

Suggest an answer

Log in or Sign up to answer