def jqlQuery = 'project = "U11" AND issuetype = Task AND status not in (Closed, "In Progress","WIP") AND ((priority = "Medium" AND created <= -1d) OR (priority = High AND created <= -21d) OR (priority = Highest AND created <= -35d) OR (priority = Low AND created <= -60d)) and cf[10075] is empty ORDER BY cf[10246], cf[10005] ASC'
if (searchResult.body.total > 0) {
searchResult.body.issues.each { issue ->
def issueKey = issue.key
def selectListFieldId = 'customfield_10075' // Replace 'customfield_10075' with your field ID
// Fetch the issue details
def issueDetails = get('/rest/api/2/issue/' + issueKey)
.asObject(Map)
.body
// Update issue field
def updateResult = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
(selectListFieldId): [value: "4"] as Map
]
])
.asString()
// Notify users
def notifyResult = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: "Issue ${issueKey} has just been updated ",
htmlBody: "Defect ${issueKey} is out of SLA now!",
to: [
users: [
[
accountId: '63060b97189e0a3a4ff283dc'
]
]
]
])
.asString()
// Send notification to webhook
def webhookUrl = 'https://hooks.slack.com/services/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'
def msg = [
text: """Defect ${issueKey} <https://tideaccount.atlassian.net/browse/${issueKey}|${issueDetails.fields.summary}> is now out of SLA. Please consider it!"""
]
def webhookResponse = post(webhookUrl)
.header('Content-Type', 'application/json')
.body(JsonOutput.toJson(msg))
.asString()
// Handle response as needed
}
} else {
// No issues match the JQL query
// Optionally, you can log a message or perform other actions here
}
import groovy.json.JsonOutput import java.net.URLEncoder
def jqlQuery = 'project = "U11" AND issuetype = Task AND status not in (Closed, "In Progress","WIP") AND ((priority = "Medium" AND created <= -1d) OR (priority = High AND created <= -21d) OR (priority = Highest AND created <= -35d) OR (priority = Low AND created <= -60d)) and cf[10075] is empty ORDER BY cf[10246], cf[10005] ASC'
def searchResult = get("/rest/api/2/search?jql=${URLEncoder.encode(jqlQuery, "UTF-8")}") .asObject(Map)
if (searchResult.body.total > 0) { searchResult.body.issues.each { issue -> def issueKey = issue.key def selectListFieldId = 'customfield_10075' // Replace 'customfield_10075' with your field ID
} else { // No issues match the JQL query // Optionally, you can log a message or perform other actions here }