/* * This script post function provides an example script for SR for Jira cloud of how to create an issue and link the created issue back to the original issue which triggered the workflow post function. * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner * license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." *///Specifythekeyoftheprojecttocreatetheissuein.defprojectKey='<ProjectKeyHere>'//Gettheissuetypetousetocreatetheissuewith
defissueType=get('/rest/api/2/issuetype').asObject(List).body
.find{it['name']=='<IssueTypeHere>'}['id']//Specifythefieldvaluestosetonthenewlycreatedissue
defnewSummary='An issue created by a post function'defnewDescription='This issue was created by a post function and was linked to the issue which created it'//Createtheissueswiththespecifiedissuetypeandsetthespecifiedfieldvalues.defcreateIssue=post('/rest/api/2/issue').header('Content-Type','application/json').body([fields:[summary:newSummary,description:newDescription,project:[key:projectKey
],issuetype:[id:issueType
]]]).asObject(Map)//Gettheissuekeyofthenewlycreatedissuesothatweareabletolinkittotheissuewhichitwascreatedfrom.defcreatedIssueKey=createIssue.body.keyasString
logger.info("The ${createdIssueKey} issue was created")//Linktheissuestogether
//Gettheissueidforthecurrentissue
defissueId=issue.id
//Createtheissuelinkbetweenbothissues
deflink=post('/rest/api/2/issueLink').header('Content-Type','application/json').body([type:[name:"<LinkTypeHere>"],outwardIssue:[id:issueId],//Thisistheissuethatthelink'starts'at
inwardIssue:[key:createdIssueKey]//You'll need to specify an issue ID or key here]).asString()//validatethattheissuelinkcreatedcorrectly
assertlink.status==201
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.