Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to Set Custom Field on Scriptrunner Scheduled Job Edited

Hello All,

I've been able to figure out how to create a scheduled job thanks to scriptrunner's documentation, however I cannot figure out how to set a custom field with it. Here's what I have so far:

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("IT").id
summary = "Monthly Storage Analysis"
issueTypeId = "10208"
reporterId = user.name
description = "Storage & Backup team,\nPlease provide the storage utilization details for backups of SQL DBs per domain that we will be using for our monthly report. For Elasticsearch, information regarding H5R domain is sufficient."
}

def validationResult = issueService.validateCreate(user, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()

def issueResult = issueService.create(user, validationResult)
log.info "Issue created: ${issueResult.issue}"

 I've found various pages on here that seem to answer this for other users but I haven't been able to get them to work.

For example, adding this leads to an error:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManafer = ComponentAccessor.getIssueManager()
def cf = customFieldManager.getCustomFieldObjectByName("Domain(s)")

issue.setCustomFieldValue(cf,"All Domains")


So in the end, I just want to set the custom field "Domain(s)" as "All Domains"

3 answers

Hi @Jose Sepulveda ,

Is the field that you're trying to set value is a Single line text field or Drop down or what it is exactly?

Cheers, Kevin

Hello @Kevin Johnson

It's a checkbox type of field.

Like Kevin Johnson likes this
0 votes

I thought on cloud ScriptRunner uses Unirest library for REST API and not the Atlassian Java Library API?

Hi @Jose Sepulveda 

Thank you for the question.

You are trying to use a server code in the cloud environment which will not work. Cloud uses the REST API's. We have an example here to set fields in our doc that you can use as an example here. Then, we have an example of how to update a checkbox field as your guide here

Hope this will help.

Kind Regards

Kate

Hello @Kate Kabir

I'm not actually sure how to tell what Jira version we have. The only choice I had was cloud though I can't tell for sure if that's what we use. If I had to guess, it'd be closer to a Jira server as I know we do have a server set up with the internals of Jira.

That being said, I've used the first code block to create issues in our Jira in the past and it's worked fine using the scriptrunner scheduled job utility. It's just that I can't get custom fields to be set upon issue creation.

Hi @Jose Sepulveda 

Thank you for the update.

I am sorry if my answer did not help you much. I believe it would be best if you can re-categorise the question as a server or create a new question for the server so that someone that is familiar with the server can assist you better.

Apologies for the inconvenience caused.

Thank you :)

Kind Regards

Kate

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
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