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"
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I thought on cloud ScriptRunner uses Unirest library for REST API and not the Atlassian Java Library API?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.