Set a custom field "User Picker" from sub task to parent task

Swarna Radha August 13, 2018

Hi,

I want to set a user picker "code reviewer" in the parent task which is copied from the sub task upon creation (Sub task Creation)

Please see my code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager


def parentIssue = (MutableIssue)issue.getParentObject()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//CustomField copyFrom = customFieldManager.getCustomFieldObject("customfield_13467")
CustomField cf2Update = customFieldManager.getCustomFieldObject("customfield_11404")
def valcf2Update = parentIssue.getCustomFieldValue(cf2Update)

parentIssue.setCustomFieldValue(cf2Update, valcf2Update)


def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

 

The code has been executed successfully but the code reviewer is not set.

Thanks

Swarna

1 answer

0 votes
Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2018

Hi @Swarna Radha,

it seems that you are getting an value from the parent issue and then set the same value to the parent issue again.

So there will be no change visble, as noting is changed.

I think you will have to uncomment the line where you get the copyFrom field and change the line where you get the value to get it from the current issue.

Swarna Radha August 13, 2018

Hi Bastian,

No, I want to set the value from the sub task to parent. When i create a sub task, it will take the value of the code reviewer and set it on the parent Task

Please see code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager


def parentIssue = (MutableIssue)issue.getParentObject()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf2Update = customFieldManager.getCustomFieldObject("customfield_11404")
def valcf2Update = parentIssue.getCustomFieldValue(cf2Update)

parentIssue.setCustomFieldValue(cf2Update, valcf2Update)


def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true

 

Thanks

Swarna

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2018

Hi @Swarna Radha,

 

I think this is the problem:

...

CustomField cf2Update = customFieldManager.getCustomFieldObject("customfield_11404")
def valcf2Update = parentIssue.getCustomFieldValue(cf2Update)

parentIssue.setCustomFieldValue(cf2Update, valcf2Update)

...

You are trying to get the value from the parent issue. Please try to replace parentIssue with issue

Swarna Radha August 13, 2018

Hi Bastian,

I have updated the code and i have added a debugger which is giving me null.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Category
log.setLevel(org.apache.log4j.Level.DEBUG)

def issue = (MutableIssue)issue.getParentObject()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf2Update = customFieldManager.getCustomFieldObject("customfield_11404")
def valcf2Update = issue.getCustomFieldValue(cf2Update)
log.debug("Code Reviewer: $valcf2Update")
issue.setCustomFieldValue(cf2Update, valcf2Update)


def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true)

 

Thanks

Swarna

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 15, 2018

Hi @Swarna Radha,

if the value is null, there is either no value or you are getting the wrong custom field, I guess.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events