Forums

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

Jira Automation - Get created issue key

Shahroz Naeem
Contributor
August 17, 2020

While using the Automation for Jira Cloud, is it possible to get the key of the issue that was created in the very same automation? 
Here's a screenshot of what I'm trying to implement. The issue is created perfectly - I just want to send the Key of the created issue over Slack/Teams/Email without using JQL/Lookup to fetch it. 
image.png

1 answer

1 vote
Jenna Davis
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 Champions.
February 28, 2018

selectedSuppliers is a list of all of the selected options from your multiselect, you need to use the 'it' variable that you get from your .each loop to assign a single value from this list to your new issue. 

Try out this code, I did not directly test it but I made a few changes that I 'think' will fix the problems you mentioned:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Issue issue = issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
int i = 0
//assuming this is a multiple select list custom field
def suppliers = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10201")
def selectedSuppliers = issue.getCustomFieldValue(suppliers)
def issueSummary = issue.summary
def issueDescription = issue.description
def issueReporter = issue.reporter

selectedSuppliers?.each {
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def newIssue = issueFactory.cloneIssue(issue)

newIssue.setIssueTypeId("10101")
newIssue.setSummary(issueSummary)
newIssue.setDescription(issueSummary)
newIssue.setReporter(issueReporter)
newIssue.setCustomFieldValue(suppliers, it.toString())

Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(currentUser, newIssueParams)
}

 If I misunderstood your issue or if you have any other questions, please let me know. :)

Jenna

João Silva Corrêa
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!
March 5, 2018

Hi Jenna,

 

Thanks for your answer, it is working now! :)

Moreover, do you have any clue on how could I set the security level based on this custom field value?

Suggest an answer

Log in or Sign up to answer