Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,684
Community Members
 
Community Events
165
Community Groups

Set custom field value [Script Runner]

Hello All,

I want to set a value for a custom field.

I try it to do it with a text field but didn't work...

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("testgroovy2")

issue.setCustomFieldValue(cf,"Its Works")

How can I fixed it?

 

if I want to do it with a select user field....what I need to add?

 

Thank you all! 

 

1 answer

1 accepted

5 votes
Answer accepted

Hello @Aitor Bermejo Cacho 

You also need to save changes with IssueManager, like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManafer = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = customFieldManager.getCustomFieldObjectByName("testgroovy2")
def userCf = customFieldManager.getCustomFieldObjectByName("user picker")

issue.setCustomFieldValue(cf,"Its Works")
issue.setCustomFieldValue(userCf, user)
issueManafer.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

 And to set User Picker, you need to pass ApplicationUser object.

Thank you @Mark Markov , its works!

but, works if the field its text field...if I use a user picker?

Like Stephane Eicher likes this

If it user picker, you need ApplicationUser object. Like in my example it sets currentUser in "user picker" field.

If you need some other user, use UserManager

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManafer = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userToSet = userManager.getUserByKey("userkey")
def userCf = customFieldManager.getCustomFieldObjectByName("user picker")

issue.setCustomFieldValue(userCf, userToSet)
issueManafer.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

I am getting this error. Could you please help me.Untitled.png

Hello @YogeshRanjit 

I think this is a typical error of beginer...

If you are doing the code in Console, please define one issue and use it.

If you are doing the code in postfunction or listened only is necessary to declare.

//Test para Console
def issueKey = "IESD-14862"
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(issueKey)
//def issue = issue as Issue
log.info("issue: "+ issue)
Like # people like this

OR

import com.atlassian.jira.user.util.UserManager

@StandardModule IssueManager issueManager

Issue issue = issueManager.getIssueByCurrentKey("ISSUEKEY-00000")

some code...

can some one help me on this I want to multiple 3 different field values and display them on 4th field

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you