Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

3 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)

Thank you!

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 haventName likes this

OR

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

@StandardModule IssueManager issueManager

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

some code...

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