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

Copy priority from parent to subtask on create screen Edited

Yashin Vladislav Apr 10, 2019

Hi,

I want to set the priority for the subtask the same as in the parent task (with the ability to change it when creating the task), but the script does not work

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript

import java.sql.Timestamp

import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours

FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long
if (!parentIssueId) {
// this is not a subtask, or the field already has data
return
}
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
getFieldById("PRIORITY").setFormValue(parentIssue.getPriorityObject().id)

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry Apr 10, 2019

Hi @Yashin Vladislav ,

Your script seems fine, but I think you need to put priority in lower case : 

getFieldById("priority").setFormValue(parentIssue.getPriorityObject().id)

 That worked on my instance.

Antoine

Yashin Vladislav Apr 10, 2019 • edited

Hi @Antoine Berry 

In my instance don't work :(

getFieldById("priority").setFormValue(parentIssue.getPriorityObject().id)

I check this in Initialiser in behavior! 

Antoine Berry Apr 11, 2019

I have been trying this script (in Initializer too) : 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours fieldBehaviours

def parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
log.error("parentIssue : " + parentIssue)

def parentPriority = parentIssue.getPriorityObject().id
log.error("parentPriority : " + parentPriority.getClass())
log.error("parentPriority : " + parentPriority)

getFieldById("priority").setFormValue(parentPriority)

and it has been working fine. I am using jira 7.6.0 with scriptrunner 5.4.12. If you are using server side script, maybe try a direct script. 

Antoine

Like Yashin Vladislav likes this
Yashin Vladislav Apr 11, 2019

@Antoine Berry 

please attach screenshot your behavior :)

Antoine Berry Apr 11, 2019

I am sorry, I thought it was in the Initializer, but it actually is bound to the Issue Type field :

image.pngAntoine

Like Yashin Vladislav likes this
Yashin Vladislav Apr 11, 2019

@Antoine Berry 

Thanks for the help :)

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

176 views 2 7
Read article

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