Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,366,177
Community Members
 
Community Events
168
Community Groups

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

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! 

1 answer

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

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
TAGS

Atlassian Community Events