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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Swarna Radha,
if the value is null, there is either no value or you are getting the wrong custom field, I guess.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.