It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,346 views 11 5
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you