Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Setting the status of an issue upon creation with a groovy script

Alexander Wittich
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 7, 2021

Hello everybody,

 

I'm currently working on a script which automatically creates a story with subtasks on the first day of each month. I'm almost done with it, but I've noticed that I can't set the status of an issue upon creation. No matter what statusId I set as a parameter, the status of the created issues are always set to the default status (the first status in the workflow after creation). So for example, I'm trying to create an issue which upon creation has the status "to Do", but the issue is always set to "Backlog" (first status in the workflow).

relevant code:

def issueStatusId = "11"

def issueInputParameters_parent = issueService.newIssueInputParameters()

issueInputParameters_parent.with {
projectId = projectManager.getProjectObjByKey(projectKey).id
summary = summaryDesc
issueTypeId = issueTypeNameId
reporterId = reporterNameId
assigneeId = assigneeNameId
description = descriptionText
statusId = issueStatusId
priorityId = priority_high.id

}


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

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



I've also tried setting the status like this:

issueInputParameters_parent.setStatusId("11")

But this returns the same result.

 

I'm aware that I can transition the issue status after creation, but I'd like to set the correct one right at creation, since my spaghetti code is already long enough.

Any help is greatly appreciated!

 

 

1 answer

1 accepted

2 votes
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2021

Welcome to the community!

There's no way to set the status on creation.  The create "transition" lands at one point in the workflow.  It's a bit like a starting a railway journey, once you've bought a ticket and got on the train, the track ends at one fixed place and you can't change where it goes.

You'll need to do what you said - fast-track transition the issue after it's finished being created.

Alexander Wittich
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 14, 2021

Thank you very much for your answer, Nic. Do you know why the method .setStatusId() even exists if every issue defaults to the first status of the associated worklflow, regardless of its value?

Like Charlie Misonne likes this

Suggest an answer

Log in or Sign up to answer