Skip to content

Instantly share code, notes, and snippets.

@vikrantyadav11
Created May 1, 2021 13:38
Show Gist options
  • Select an option

  • Save vikrantyadav11/d66a5cf60d4b03cdd2ee97c592dffbe2 to your computer and use it in GitHub Desktop.

Select an option

Save vikrantyadav11/d66a5cf60d4b03cdd2ee97c592dffbe2 to your computer and use it in GitHub Desktop.
Create new jira issue using script runner
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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment