Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

creating a issue based on a postfunction in script runner

Alex Sprague March 3, 2021

// the project key under which the issue will get created

def projectKey = issue.fields.project.key

// the issue type for the new issue
final String issueTypeName = 'Feasibility Study'


// the summary of the new issue
final String summary = 'Feasibility Study PARENT'


def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

def Duedate = customFields.find { it.name == 'Date Due' }?.id


def taskType = get('/rest/api/2/issuetype')
.asObject(List)
.body
.find { (it as Map).name == 'Feasibility Study' } as Map

def taskTypeId = taskType.id

post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body([
fields: [
project : [
key: projectKey
],
issuetype: [
id: taskTypeId
],
summary : summary,
'Due Date' : [
Duedate : '{{now.plusBusinessDays(45)}}'
]
]
])
.asString().body

 

 

 

 

 

Based on the above code for the def projectKey = issue.fields.project.key  Is this the correct way to set the ProjectKey to whatever the project is that we are creating an issue in? I am trying to put together a script that is robust enough so I can use this within a scripted postfunction using scriptrunner. Currently it gives me a error.

1 answer

0 votes
Ravi Sagar _Sparxsys_
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.
March 3, 2021

What is the error?

Alex Sprague March 3, 2021

the error is " The variable [issue] is undeclared.

Ravi Sagar _Sparxsys_
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.
March 3, 2021

The code works for me perfectly. You are on Jira Cloud right?

Alex Sprague March 3, 2021

Correct. I am on Jira Cloud, I guess i need to try saving it and seeing if it works on my end even ignoring the error warning.

Alex Sprague March 3, 2021

So i ran the script and the only thing it trips up on is the duedate field. which is a system field within the issue body.  I have tried many variations of date strings but it acts like scriptrunner for Jira Cloud does not accept smart values. Any ideas on what i could use to resolve this?

{"duedate":"Error parsing date string: {{now.plusBusinessDays(20)}}"}}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events