Copy priority from parent to subtask on create screen

Yashin Vladislav April 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
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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 April 10, 2019

Hi @Antoine Berry 

In my instance don't work :(

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

I check this in Initialiser in behavior! 

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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 April 11, 2019

@Antoine Berry 

please attach screenshot your behavior :)

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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 April 11, 2019

@Antoine Berry 

Thanks for the help :)

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events