Automated issue status change using ScriptRunner Services

Gleb Kartashov July 31, 2019

Hi!

I need to automatically transition an issue to another status when a datetime custom field reaches current time. How could I implement this using Adaptavist ScriptRunner plugin?

1 answer

0 votes
Alexander Bondarev
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 Leaders.
July 31, 2019

Hi , you can try Listeners.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2019

You might find https://library.adaptavist.com/search?q=transition helpful when looking to write scripts for transitions on issues.

Gleb Kartashov July 31, 2019

But Listeners require a special event to occur to act. I dont have any events going on, the issue might not change at all. I want it to transition when the time's right. Is this possible when using Listeners?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2019

No, listeners need an event.

But you could easily write a service that regularly runs a filter such as "due date is  today" or "updated over a week ago" and transitions any issues it finds (Obviously, I'd recommend much more careful filters than I've just suggested)

Gleb Kartashov July 31, 2019

This is why I wanted to use service over listener. This is literally in my original question. Can I get more help on services?

Gleb Kartashov July 31, 2019

Here's my code.

Also how do I get multiple issues to use this with JQL?

// INF 31.07.2019
// source: https://community.atlassian.com/t5/Answers-Developer-Questions/Proper-way-to-change-issue-status-in-code/qaq-p/535798

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import java.util.Date;
import java.util.ArrayList;
import java.util.stream.Collectors;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;

/* The object facade class */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
MutableIssue issue1 = getIssueObject();

/* The reference to the object facade which you can use in your code */
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
def deadLine = issue1.get("customfield_11210") //deadline CustomField
def now = new Date();
deadLine = new Date(deadLine.getTime())
if(now.compareTo(deadline) >= 0){
final String remoteuser = ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName();
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue1);
workflowTransitionUtil.setUsername(remoteuser);
workflowTransitionUtil.setAction(441);//Id of the status you want to transition to
workflowTransitionUtil.progress();
}
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2019
Yury Lubanets August 2, 2019

Hi Gleb

You can try the following

You need to create a Scriptrunner's Escalation service. Then you will be able to point a JQL query. Something like this: project = 'Some Project' and "deadline" >= startOfDay() and "deadline" <= startOfDay()

Also, you will be able to choose CRON Expression and Action (Transition).

Gleb Kartashov August 2, 2019

Yeah I've already found Escalation services myself. But thanks anyway!

Suggest an answer

Log in or Sign up to answer