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 @
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yaa we use script runner can you help with code and which post fuction to use
Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What does the logs return if you add :
log.error("parent issue : " + issue.getParentObject())
log.error("user picker : " + userPicker)
between line 6 and 7 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See, user picker is null, is 12803 the correct ID ? You mentioned 11907 before.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now that is a lot of post functions ! If you log the value of userPickerValue, what do you get ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not sure about that can you tell how to log user picker value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
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.
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.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.