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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,456,480
Community Members
 
Community Events
176
Community Groups

How to set custom field value on new create issue on scriptrunner

Hi Community,

I have this piece of script which is suppose to create a ticket and set value to them.


def issueObject = issueFactory.getIssue()
def cfParticipant = "sd.request.participants.field.name"
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(MailUtils.getBody(message))
issueObject.setIssueTypeId(project.issueTypes.find {it.name == "Service Request"}.id)
issueObject.setReporter(reportermail)

issueObject.setCustomFieldValue(cfParticipant, "addresses")


messageHandlerContext.createIssue(user, issueObject)

 

But the problem is that it is not setting value for the custom field : "sd.request.participants.field.name"

 

Can I get some advice please.

 

Best regards,

Jason Li

1 answer

1 accepted

2 votes
Answer accepted

Hi Jason,

Do you recall where you found this snippet? The first argument to setCustomFieldValue needs to be a CustomField object rather than a plain string:

def cfParticipant = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Request participants")

The above assumes that you have ComponentAccessor imported; if not, you can do so at the top of your script as follows:

import com.atlassian.jira.component.ComponentAccessor

Note also that ScriptRunner will issue a deprecation warning against the use of getCustomFieldObjectByName. It is safe to ignore this, although for maximum futureproofing you may prefer to replace that call with the following:

getCustomFieldObjectsByName("Request participants")[0]

Regards,

Joanna Choules, Adaptavist Product Support

Hi Joanna.

Thank you very much for your help. I have been able to sort the problem.

 

Best regards,

Jason

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events