Forums

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

Groovy script to update value to custom field with value of current user

Heshan Manamperi
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.
November 28, 2018

Groovy script to update value to custom field with value of current user

1 answer

0 votes
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.
November 28, 2018

This should cover most of the code you need, although you haven't told us where it will be running, which may adjust what you do and how you get the current user.

https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-in-jira

Heshan Manamperi
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.
November 29, 2018

Thanks Nic for the feedback. I'm planning to use it as a workflow post function

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.
November 29, 2018

Ok, from memory, the current user is ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

That might have changed for Jira 7, it's been a while since I needed it in a post-function

Heshan Manamperi
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.
December 6, 2018

Thanks Nic for the reply. 

above returns "username(username)". how can I get just username?

May I know the function to get current issue id (JIRA 7)?

Heshan Manamperi
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.
December 6, 2018

in simply, I need to change value for current issue, not for the given ticket id in below script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.label.Label

def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueByCurrentKey("JRA-1")
def user = issue.getReporter()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//How to set a text field
def stringValue = "This value goes in a text field"
def myTextField = customFieldManager.getCustomFieldObject("textFieldId")
issue.setCustomFieldValue(myTextField, stringValue)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events