Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

creating assignee from custom field value

Surender Reddy May 23, 2019

Hi friends,

      I am creating 3 subtasks with Quick Subtasks for JIRA post function which looks like

 Creates the following subtasks according to this subtask template: 

- NSS /  cfield:"Project Title:@inherit" cfield:"Date Request Received:@inherit"
	

The issue type for the subtasks is set to Access Termination NSS.
Created subtasks are prefixed by their parent issues summary: Yes .

 

this creates subtask my question of how can I add an assignee automatically from a custom field(user picker) value from parent. which code should I add? I tried some but failing to pull assignee from the custom field(user picker). please help @Antoine Berry @Tarun Sapra @

3 answers

2 accepted

0 votes
Answer accepted
Surender Reddy May 31, 2019

Time (on server): Wed May 29 2019 09:55:25 GMT-0400 (Eastern Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-05-29 09:55:25,898 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-05-29 09:55:25,899 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EAP-444, actionId: 1, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$7.call(Unknown Source)
 at Script84.run(Script84.groovy:7)

this is the error I am seeing can you help     @Antoine Berry  

0 votes
Answer accepted
Antoine Berry
Community Champion
May 24, 2019

Hi @Surender Reddy ,

I do not use Quick Subtasks. Unfortunately, according to the documentation, it seems that you can only use @admin, @current or @inherit. 

I could help if you have scriptrunner though.

Antoine

Surender Reddy May 24, 2019

yaa we use script runner  can you help with code and which post fuction to use 

 

Thanks in advance

Antoine Berry
Community Champion
May 24, 2019

You should use a custom script post-function in the create transition of the sub-task workflow.

Use this code (replace the custom field id) : 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 12803
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
def userPickerValue = issue.getParentObject()?.getCustomFieldValue(userPicker)
issue.setAssignee(userPickerValue)

Antoine

Surender Reddy May 24, 2019

image.pngits showing error can see that please

Antoine Berry
Community Champion
May 27, 2019

Hi @Surender Reddy , 

Please save as is. It is showing an error because the groovy console is not detecting userPickerValue as an ApplicationUser object, but at execution time it will work.

Antoine

Surender Reddy May 29, 2019

Time (on server): Wed May 29 2019 09:55:25 GMT-0400 (Eastern Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-05-29 09:55:25,898 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-05-29 09:55:25,899 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EAP-444, actionId: 1, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$7.call(Unknown Source)
 at Script84.run(Script84.groovy:7)

this is the error I am seeing can you help

Antoine Berry
Community Champion
June 3, 2019

Hi @Surender Reddy ,

You are using this script in a create transition right ? Make sure you make it the last postfunction. Also can you confirm the issue is created as a subtask ?

Antoine

Surender Reddy June 3, 2019

yes its in create transtion and this is the last post function .  this issue is created using multiple subtask post function in parent issue

Creates the following subtasks according to this subtask template: 

- Security Groups /  cfield:"Project Title:@inherit" cfield:"Date Request Received:@inherit"

and the custom feilds are inherited from parent issue using  

 

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor


//Your custom field ID
int cfId = 11902
def cf = customFieldManager.getCustomFieldObject(cfId)
def cfValue = issue.getCustomFieldValue(cf)
def cfParentValue = issue.getParentObject().getCustomFieldValue(cf)

cf.updateValue(null, issue, new ModifiedValue(cfValue, cfParentValue), new DefaultIssueChangeHolder())

 

in a scriptrunner post funtion .  @Antoine Berry 

Antoine Berry
Community Champion
June 3, 2019

What does the logs return if you add : 

log.error("parent issue : " + issue.getParentObject()) 
log.error("user picker : " + userPicker)

between line 6 and 7 ?

Surender Reddy June 3, 2019

sorry i did not get you what do you want me to add between 6 and 7 lines , i only have the code which you sent me 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 12803
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
def userPickerValue = issue.getParentObject()?.getCustomFieldValue(userPicker)
issue.setAssignee(userPickerValue)

and the error for this code is  

 

Time (on server): Mon Jun 03 2019 11:18:12 GMT-0400 (Eastern Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-06-03 11:18:12,488 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-06-03 11:18:12,492 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EAP-462, actionId: 1, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$4.call(Unknown Source)
 at Script108.run(Script108.groovy:7)
Antoine Berry
Community Champion
June 3, 2019

Yes, can you use this code instead : 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 12803
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
log.error("parent issue : " + issue.getParentObject())
log.error("user picker : " + userPicker)
def userPickerValue = issue.getParentObject()?.getCustomFieldValue(userPicker)
issue.setAssignee(userPickerValue)

Trying to track what is null here.

Like Surender Reddy likes this
Surender Reddy June 3, 2019

Still, there is an error showing, the transition is getting successful but post function is failing.

 

Time (on server): Mon Jun 03 2019 11:45:49 GMT-0400 (Eastern Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-06-03 11:45:49,954 ERROR [workflow.ScriptWorkflowFunction]: parent issue : EAP-436
2019-06-03 11:45:49,954 ERROR [workflow.ScriptWorkflowFunction]: user picker : null
2019-06-03 11:45:49,956 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-06-03 11:45:49,956 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: EAP-465, actionId: 1, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$4.call(Unknown Source)
 at Script115.run(Script115.groovy:9)


Antoine Berry
Community Champion
June 3, 2019

See, user picker is null, is 12803 the correct ID ? You mentioned  11907 before.

Like Surender Reddy likes this
Surender Reddy June 3, 2019

yaa sorry I was changing the code from few days so forgot that and the post function is successful now, no logs found. but the problem is the assignee of the subtask is still unassigned.

 

image.png

Antoine Berry
Community Champion
June 4, 2019

Now that is a lot of post functions ! If you log the value of userPickerValue, what do you get ?

Like Surender Reddy likes this
Surender Reddy June 4, 2019

I am not sure about that can you tell how to log user picker value

Antoine Berry
Community Champion
June 4, 2019

use 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 11907
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
def userPickerValue = issue.getParentObject()?.getCustomFieldValue(userPicker)
log.error("userPickerValue : " + userPickerValue)
issue.setAssignee(userPickerValue)

 and paste the logs

Like Surender Reddy likes this
Surender Reddy June 4, 2019

it's returning the value of the custom field which is Eid of the Hiring manager. 

2019-06-04 10:51:33,722 ERROR [workflow.ScriptWorkflowFunction]: userPickerValue : e0o12mw(e0o12mw)
Antoine Berry
Community Champion
June 4, 2019

Try this, I added two lines : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.IssueIndexingService

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 11907
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
def userPickerValue = issue.getParentObject()?.getCustomFieldValue(userPicker)
issue.setAssignee(userPickerValue)

issue.store()
ComponentAccessor.getComponent(IssueIndexingService).reIndex(issue)
Like Surender Reddy likes this
Surender Reddy June 4, 2019

super super 

Its working hiring manager field value updated in subtasks assignee ..

great work @Antoine BerryBerry. Thank you so much for being with the issue until the end .

Like Antoine Berry likes this
Antoine Berry
Community Champion
June 4, 2019

No problem ! Glad it worked out.

Cheers.

Like David P_ Hicks likes this
0 votes
Yashwanth Jakkula October 19, 2022

Hi,

My requirement is - Set assignee Automatically based on field value called Approver within same issue, used below script, but not working. Execution is success but Assignee value is not changed.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.IssueIndexingService

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int userPickerId = 28200
def userPicker = customFieldManager.getCustomFieldObject(userPickerId)
def userPickerValue = issue.getCustomFieldValue(userPicker)
issue.setAssignee(userPickerValue)

issue.store()
ComponentAccessor.getComponent(IssueIndexingService).reIndex(issue)
Yashwanth Jakkula October 20, 2022

Made small change, it's working now.

 

Thanks!

Suggest an answer

Log in or Sign up to answer