Forums

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

ScriptRunner: Copy Assignee field to Custom Field during Post Function

Bogdan Gorka
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.
October 14, 2019

I want to use Script Runner to copy current Assignee to a custom text field 'Resolved by' using the post function during the last transition, which is resolving the issue. I simply want to be able to report on who resolved the issue.

For some reason this script I have developed doesn't work. I will appreciate any help to get this right.

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def userCf = customFieldManager.getCustomFieldObjectByName("Resolved by")
def assignee = issue.getAssignee()

issue.setCustomFieldValue(userCf, assignee)

 

2 answers

0 votes
Tuncay Senturk
Community Champion
October 15, 2019

Or you can try this one

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userCf = customFieldManager.getCustomFieldObjectByName("Resolved by")
def changeHolder = new DefaultIssueChangeHolder()
def oldValue = issue.getCustomFieldValue(textCf2)
def newValue = issue.getAssignee()
userCf.updateValue(null, issue, new ModifiedValue(oldValue, newValue),changeHolder)

I did not test the code, please let us know the result ;)

Thanks

Bogdan Gorka
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.
October 15, 2019

Your solutions did not help me unfortunately. I have come across a few other solutions including this https://community.atlassian.com/t5/Jira-questions/Copy-worklog-to-custom-field/qaq-p/239258 but the task turned out to be too difficult.

I need to give up on this idea for now. Thank you for your help.

0 votes
Tuncay Senturk
Community Champion
October 15, 2019

Hi @Bogdan Gorka 

Could you please try with adding below line after setCustomFieldValue?

def issueManager = ComponentAccessor.getIssueManager()
issueManager
.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

And please give us more details, are you getting an error?

Suggest an answer

Log in or Sign up to answer