Forums

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

Automatically assign to a user from a custom field

Ashley Roberts May 1, 2023

I am trying to have issues assigned to a user that is in a customer field when an issue reaches a certain state in a workflow.

I have looked at adding a post function and I can see an option to use. I have looked at "Copy field values" and I can select the source field but can select the Assignee field in the target field.

As shown in the screenshot.

Test Lead screenshot.JPG

Please can someone suggest how I can get this into the workflow?

2 answers

0 votes
Vikrant Yadav
Community Champion
May 3, 2023

Hi @Ashley Roberts I think you are using Script Runner Copy Field value post function. This post function won't support Assignee and Reporter field. 

Kindly create a scripted post function for this. Test lead is user picker custom field ? 

0 votes
Alex Koxaras -Relational-
Community Champion
May 1, 2023

Hi @Ashley Roberts 

Can you please explain what do you mean by "customer"? Usually a customer can be found on JSM projects. And you can't really assigned anything to a customer, unless this customer has a valid JSM license and has the "assignable" permission.

Ashley Roberts May 2, 2023

Sorry, that should have read "custom field" not "customer field".

Alex Koxaras -Relational-
Community Champion
May 2, 2023

@Ashley Roberts hi!

Thanx for the clarification. So you want to copy the assignee onto a custom field, or vice versa? Which post function do you use?

Ashley Roberts May 2, 2023

I was thinking of using "Copy field values from one field to another"

I can get the custom field showing in the source field, but I can't get the Assignee field to show in the Target Field.

Test Lead screenshot2.JPG

Alex Koxaras -Relational-
Community Champion
May 3, 2023

@Vikrant Yadav has a keen eye, and you are indeed using Scriptrunner. Based on their documentation:

All text and select custom fields are supported, as well the the SummaryDescription, and Environment system fields. 

https://docs.adaptavist.com/sr4js/6.31.0/features/built-in-scripts/copy-field-values

So in other words this post function will not let you copy the field to assignee. Do you have another app to use like JMWE? If not, then use the custom script from scriptrunner and try to follow the instructions on this post https://community.atlassian.com/t5/Jira-questions/Script-to-copy-Assignee-field-to-other-userpicker-custom-field/qaq-p/1061704 (but in reverse)

Like Vikrant Yadav likes this
Ashley Roberts May 3, 2023

I have created the following script in Scriptrunner but it does not work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def assigneeField = ComponentAccessor.getFieldManager().getFieldByName("Assignee")
def customField = customFieldManager.getCustomFieldObjectByName("Test Lead")

issue = event.issue as MutableIssue
def user = issue.getCustomFieldValue(customField) as ApplicationUser

if (user && issue.getStatusObject().getName() == "Awaiting Closure") {
issue.setAssignee(user)
}

 

ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue ****** for user '*****'. View here: https://************/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=*******Workflow&descriptorTab=postfunctions&workflowTransition=61&highlight=1
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.DefaultFieldManager.getFieldByName() is applicable for argument types: (String) values: [Assignee]
at Script15.run(Script15.groovy:6)

Sorry, due to the nature of where I work, I need to redact some of the information out of the error.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2023

This is because assignee is not a field, its part of the issue.

You can use issue.getAssignee() and issue.setAssignee(Application-user) to work with it.

Or, if you aon a recent version of Scriptrunner, one with HAPI in it, something like the below (which needs no imports)

Issues.getByKey('SR-1').update {
setAssignee('jdoe')
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.13
TAGS
AUG Leaders

Atlassian Community Events