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] (ComponentManager has been deprecated)

I'm trying to create and populate custom fields and options. The example code I found uses the ComponentManager:

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)

ComponentManager has been deprecated since JIRA 7.11.

I can not find any example code that works in the Script Console.

Can any one out there give me a hand, or point in the right direction.

 

2 answers

this is a good example, but if you want to use it in console, you need to define issue object before you try to use it:

def issue = issueManager.getIssueObject("JIRA-123")

otherwise it looks like either postfunction or listener piece of code

Hello, 

i do 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")

def issue = issueManager.getIssueObject("JIRA-123")

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

but  i have this error :

Capture d’écran (7).png

2020-12-23 18:38:27,266 INFO [runner.ScriptBindingsManager]: cf: [] 2020-12-23 18:38:27,266 INFO [runner.ScriptBindingsManager]: userCf: [] 2020-12-23 18:38:27,266 INFO [runner.ScriptBindingsManager]: issue: JIRA-123 2020-12-23 18:38:27,270 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2020-12-23 18:38:27,270 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (com.google.common.collect.RegularImmutableList, String) values: [[], Its Works] Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField) at Script911.run(Script911.groovy:40)

 Please can you help me ? 

Thanks 

BR

Fayçal

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