Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

scriptrunner plugin

Yuriev Aleksey
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!
January 19, 2022

Good afternoon. There is a script runner plugin, which for some reason does not work quite correctly, maybe I missed some settings in the fat itself. There is a certain code, it creates a task in which the performer and the leader of the performer are linked, but for some reason the link to the leader does not come k1TL0DSMBq8.jpg

 String linkName = "Объяснение"
String projectKey = "CHECKS"
String taskTypeId = 10812 //Объяснение
String jql = "filter=14612"
Long startAt = 0
Long maxResults = 100
Long total = 1
while (startAt < total) {
//logger.info("startAt=${startAt}, maxResults=${maxResults}, total=${total}")
def response = get("/rest/api/2/search?startAt=${startAt}&maxResults=${maxResults}&jql=${jql}")
.header('Content-Type', 'application/json')
.asObject(Map)

response.body.issues.each { issue ->
//Отсечём задачи в которых текущий исполнитель - неактивный пользователь.
def responseAssignee = get("/rest/api/2/user?accountId=${issue.fields.assignee.accountId}")
.header('Content-Type', 'application/json')
.asObject(Map)
boolean assigneeIsActive = responseAssignee.body.active
if(assigneeIsActive){
createLinkedIssue(issue, projectKey, taskTypeId, linkName)
}
}
startAt += maxResults
total = response.body.total

}
def createLinkedIssue(issue, projectKey, taskTypeId, linkName) {
//создание задачи и линковка
Date date = new Date() +1
Calendar calendar = Calendar.getInstance()
calendar.setTime(date)

String dueDate = "${calendar.get(Calendar.YEAR)}-${addZeros(calendar.get(Calendar.MONTH)+1)}-${addZeros(calendar.get(Calendar.DAY_OF_MONTH))}"
//создание задачи
newIssueResult = post('/rest/api/3/issue')
.header('Content-Type', 'application/json')
.body([
fields: [
summary : "Обяснительная по задаче ${issue.key}",
description: [
"type": "doc",
"version": 1,
"content": [
[
"type": "paragraph",
"content": [
[
"type": "mention",
"attrs": [
"id": issue.fields.assignee.accountId,
"userType": "APP"
]
],
[
"type": "text",
"text": ", просьба указать причину просрочки по задаче ${issue.key}.\nСделать это можно по кнопке \"Направить отчёт\"\n\n@Руководитель, просьба классифицировать просрочку.\nСделать это можно по кнопке \"Классифицировать по причинам\""
]
]
]
]
],
project : [
key: projectKey
],
issuetype : [
id: taskTypeId
],
reporter: [
"id": issue.fields.reporter.accountId
],
assignee: [
"id": issue.fields.assignee.accountId
],
duedate: dueDate
]
])
.asObject(Map)
newIssueKey = newIssueResult.body.key
oldIssueKey = issue.key
logger.info("newIssueKey=${newIssueKey}")
//линковка задачи
post("/rest/api/3/issueLink")
.header('Content-Type', 'application/json')
.body([
"outwardIssue": ["key": oldIssueKey],
"inwardIssue": ["key": newIssueKey],
"type": ["name": linkName]
]).asObject(Map)
}
String addZeros(Integer i){
if(i < 10){
return "0${i}"
}else{
return "${i}"
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events