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

set value of custom field in scriptrunner scheduled job Edited

I'm using Jira server ver 8.13.3

I have a text based custom field called "Deliverables" and I'm trying to create a Custom scheduled job to create an issuetype story every day with the "Deliverables" field set to "insert custom text". 

Deliverables = customfield_13518

I've tried the following but it never actually injects the text into the custom field

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = Component.Accessor.customFieldManager()
def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("PROJ").id
summary = "reoccurring task"
issueTypeId = "21"
reporterId = user.name
description = "Daily Task Checklist"
customfield_13518 = "Submit Form 1362"
}

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

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

1 answer

Hi @David Howe Try to insert value in custom field using below code :- 

issueInputParameters.addCustomFieldValue(cf.idAsLong, requestTypeValue)

Hi @David Howe  :- Working Code for me :- 

 

import com.atlassian.jira.component.ComponentAccessor

def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def requestTypeValue = "Submit Form 1362" //replace it with the one you want - see note below

def constantsManager = ComponentAccessor.getConstantsManager()
def issueType = constantsManager.getAllIssueTypeObjects().find {it.name.equalsIgnoreCase("New Project Request")}
def issueInputParameters = issueService.newIssueInputParameters()
def customFiledmanager = ComponentAccessor.getCustomFieldManager()
def cf = customFiledmanager.getCustomFieldObjectByName("CA Ticket#")

issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("CJS").id
summary = "Issue created from script"
issueTypeId = issueType.getId()
reporterId = "vikrant-yadav2"
assigneeId = "vikrant-yadav2"
}

issueInputParameters.addCustomFieldValue(cf.idAsLong, requestTypeValue)
def validationResult = issueService.validateCreate(user, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()

def issueResult = issueService.create(user, validationResult)

assert !issueResult.errorCollection.hasAnyErrors()
return "Issue created: ${issueResult.issue}"

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