Forums

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

ScriptRunner Escalation Services throws an exception

Deleted user April 1, 2022

Hello everybody!

I have a need to periodically delete requests in JIRA. To do this, I use the Escalation Services module of the Script Runner plugin and the following code

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

try {
IssueManager issueManager = ComponentAccessor.getIssueManager()
ComponentAccessor.issueManager.deleteIssueNoEvent(issue as Issue)
} catch (Exception exception) {
log.warn("Exception" + exception.getMessage())
}

And requests are deleted without problems. But when executed, the following information is recorded in the logs, regardless of whether the try - catch block is used in the code or not

2022-04-01 11:56:17,586 ERROR [admin.EscalationService]: Escalation Service (Удаление запросов, если в запросе есть комментарий - Удалить) failed for issue 3-30
java.lang.Exception: Not attempting update. Errors: {}
Error Messages: [Вы не можете обновить пустой запрос.]
at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils.updateIssue(WorkflowUtils.groovy:259)
at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils.updateIssue(WorkflowUtils.groovy)
at com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils$updateIssue$0.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.admin.EscalationService$_runService_closure4.doCall(EscalationService.groovy:420)
at com.onresolve.scriptrunner.canned.jira.admin.EscalationService.runService(EscalationService.groovy:386)
at com.onresolve.scriptrunner.canned.jira.admin.EscalationService.getDescription(EscalationService.groovy:342)

 Tell me which exception needs to be handled so that errors do not appear in the logs?

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 9, 2022

Hi @[deleted]

If you intend to delete and issue via ScriptRunner's Jobs, the Escalation Service is not the correct approach.

Instead, you will need to use the Custom Jobs feature.

Below is a sample working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.issueManager

def query = jqlQueryParser.parseQuery("project = 'MOCK' and type = 'Story' and status = 'Done'")
def search = searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter)

search.results.each {
def issue = issueManager.getIssueObject(it.id) as Issue
issueManager.deleteIssue(loggedInUser, issue, EventDispatchOption.ISSUE_DELETED, false)
}
return null

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

You will need to modify the JQL Query provided in the sample code above, i.e.:-

def query = jqlQueryParser.parseQuery("project = 'MOCK' and type = 'Story' and status = 'Done'")

to suit your requirements.

Also, the return null parameter is required at the very ending sot that it will not return any error messages.

Below is a print screen of the Custom Jobs configuration:-

custom_jobs.png

 

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events