Hello everyone,
The idea is the following:
I import automatically a list of issues by email for a recruitment Jira board.
On those issues, the summary is something like: "New application: Network Engineer from First_Name Last_Name"
I want to run a script on very first transition (issue created) which transforms this summary:
- removes first 17 chars ("New application:")
- saves job title and populates a custom field with it
- new summary value should be "First_Name Last_Name"
I tried a lot to get the summary value as a string to be able to work on it but whatever I do, I cannot get that value at all.
My code now looks something like this:
// Define a JQL query to search for the issues on which you want to set the impediment flag
def query = "some_query"
// Search for the issues we want to update
def searchReq = get("/rest/api/2/search")
.queryString("jql", query)
.asObject(Map)
// Verify the search completed successfully
assert searchReq.status == 200
// Save the search results as a Map
Map searchResult = searchReq.body
// Iterate through the search results and set the summary and custom field value for each issue returned
searchResult.issues.each { Map issue ->
String sum = (issue.fields.summary as String)
if (sum.toLowerCase().contains('new application:')) {
// Trim and split the summary
sum = sum.substring(17)
String new_summary = sum.split('from ');
//Update the summary and the custom field
def result = put('/rest/api/2/issue/' + issue.key)
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields:[
issue.fields['10102'] : new_summary[0],
summary: new_summary[1]
]
]),
.asString();
// Log out the issues updated or which failed to update
if (result.status == 204) {
logger.info("The ${issue.key} issue was flagged as an Impediment. ")
} else {
logger.warn("Failed to set the summary on the ${issue.key} issue. ${result.status}: ${result.body}")
}
}
} // end of loop
return "Script Completed - Check the Logs tab for information on which issues were updated."
I get an error saying that the summary variable is not defined here:
String sum = (issue.fields.summary as String)
Can someone please help me?