Forums

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

Creating a sub-tsk via scriptrunner gives an error even using the example given.

Lori Blatt
April 27, 2023
Here is the code in scriptrunner:

// Specify the key of the parent issue here
def parentKey = 'FN-29722'

// Get the parent issue type
def issueResp = get("/rest/api/2/issue/${parentKey}")
.asObject(Map)
assert issueResp.status == 200

// get the body of the parent issue type
def issue = issueResp.body as Map

// Get the issue types for the instance
def typeResp = get('/rest/api/2/issuetype')
.asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>


// Here we set the basic subtask issue details
def summary = "DEV::BATCH - test" // The summary to use for
def issueType = "Sub-task" // The Sub Task Issue Type to Use

// Get the sub task issue type to use
def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
assert issueTypeId : "No subtasks issue type found called '${issueType}'"

// Get the project to create the subtask in
def project = (issue.fields as Map).project

// Create the subtask
def resp = post("/rest/api/2/issue")
.header("Content-Type", "application/json")
.body(
fields: [
project: project,
issuetype: [
id: issueTypeId
],
parent: [
id: issue.id
],
summary: summary
])
.asObject(Map)

// Get and validate the newly created subtask
def subtask = resp.body
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null

// If the sub task created successfully return a success message along with its key
if (resp.status == 201) {
return 'Success - Sub Task Created with the key of ' + resp.body.key.toString()
} else {
return "${resp.status}: ${resp.body}"
}

 

 

Here is the error:

 

Serializing object into 'interface java.util.Map'
GET /rest/api/2/issue/FN-29722 asObject Request Duration: 659ms
Serializing object into 'interface java.util.List'
GET /rest/api/2/issuetype asObject Request Duration: 316ms
Serializing object into 'interface java.util.Map'
POST /rest/api/2/issue asObject Request Duration: 564ms
POST request to /rest/api/2/issue returned an error code: status: 400 - Bad Request
body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
Assertion failed: 

assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
       |    |      |      |  |    |      |     |          |
       |    400    true   |  |    400    false false      false
       |                  |  status: 400 - Bad Request
       |                  |  body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}
       |                  false
       status: 400 - Bad Request
       body: {errorMessages=[], errors={issuetype=The issue type selected is invalid., project=Issues with this Issue Type must be created in the same project as the parent.}}

Class: com.adaptavist.sr.cloud.events.ConsoleScriptExecution, Config: [userTriggered:true]

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
SMS
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 15, 2017

Hi Nicholas,

Can you show us what the formatting looks like when it's not working? Please also let me know an example page in your Cloud instance that I can have a look at to see what might be going wrong.

Kind Regards,
Shannon

Nick
Contributor
September 15, 2017

Thanks for the response Shannon,

 

You can see the sample page, and here is a screenshot:

Screen Shot 2017-09-15 at 10.24.43 AM.png

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 15, 2017

Hi Nicolas - Shannon is off shift now but I have been investigating this issue in her absence.

On my Confluence Cloud test instance, I restored the storage format from the sample page you linked. I found the same behavior you are reporting. If I preview the page the style is applied to the TOC macro but when I publish, the headings are all the same weight, just as in your screen shots.

I noticed that the TOC was in a div macro so I tried it outside that macro and got the same result. 

Although the div and style macros are there by default in Confluence Cloud, they are actually provided by a third party plugin, as mentioned in Macros:

Adaptavist Content Formatting macros

...This free add-on is enabled by default in your site, and includes the wiki markup based {style}, {div}, {table} and other macros that you might see in the macro browser.

I am going to move your question to Adaptavist's collection on the Community forum, to get the attention of the Adaptavist team.

I will be watching this thread as I am curious why the formatting is lost when the page is published.

Preview:

 

Screen Shot 2017-09-15 at 5.29.35 PM.png

Screen Shot 2017-09-15 at 5.29.35 PM.png

Screen Shot 2017-09-15 at 5.29.35 PM.png

Screen Shot 2017-09-15 at 5.29.35 PM.png

Screen Shot 2017-09-15 at 5.29.35 PM.png

Screen Shot 2017-09-15 at 5.29.35 PM.png

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 15, 2017

Published:

Screen Shot 2017-09-15 at 5.29.57 PM.png

Screen Shot 2017-09-15 at 5.29.57 PM.png

AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 15, 2017

Oh boy - I am having an issue with the editor. It has been reported internally.

TAGS
AUG Leaders

Atlassian Community Events