/** This example script console script shows how to create an Epic Issue and then create a story issue inside it. * "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." */// NOTE - The Epic Link field must be pressent on the create screen in the Project where the Story issues are being created. // Specify the Project Key for the project to create the issues in belowdefprojectKey=''defprojectId=get("/rest/api/2/project/${projectKey}").asObject(Map).body.id// Get the Ids for the Epic and Story Issue typesdefepicType=get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find{it['name']=='Epic'}['id']defstoryType=get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find{it['name']=='Story'}['id']// Get all custom fieldsdefcustomFields=get("/rest/api/3/field").asObject(List).body.findAll{(itasMap).custom}asList<Map>// Get the ID for your the Epic Link fielddefepicLinkField=customFields.find{it.name=='Epic Link'}?.id// Create the Epic issuedefcreateEpic=post('/rest/api/2/issue').header('Content-Type','application/json').body([fields:[summary:'Sample Epic',project:[key:projectKey],issuetype:[id:epicType]]]).asObject(Map)// Validate that the Epic was created correctlyassertcreateEpic.status>200&&createEpic.status<300// Get the issue key for the newly created Epic. defcreatedEpicKey=createEpic.body.key;// Create the story and link it to the created EpicdefcreateStory=post('/rest/api/2/issue').header('Content-Type','application/json').body([fields:[summary:'Sample Story',(epicLinkField):createdEpicKey,project:[key:projectKey],issuetype:[id:storyType]]]).asObject(Map)// Validate that the Story was created correctlyassertcreateStory.status>200&&createStory.status<300// Return details of the Key of the Epic and Story issue that was createdreturn"An Epic was created with the key of: ${createdEpicKey} and has the story with the key of: ${createStory.body.key} created inside it."
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.