[scriptrunner] set assignee

arno
Contributor
February 28, 2025

Hi all

    Some of our colleagues leave the company regularly, and the issue is not transferred to the corresponding colleague before leaving the company, which leads to the failure to deal with some issues in time

     I learned that trial scriptrunner can determine whether users are dimission based on assignee status. Can I set up a regular check when the handler status changes and automatically assign it to someone else

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 1, 2025

Hi @arno ,

you can setup a script runner job for this purpose (https://docs.adaptavist.com/sr4js/9.5.0/features/jobs). Using jira api you can check status of the assignee and, based on that, define what to do .

In this example issue for specific JQL will be re-assigned to Project Lead if assignee is not active anymore.

 

import java.util.ArrayList;

import java.util.List;

 

import com.atlassian.crowd.embedded.api.Group;

import com.atlassian.jira.bc.issue.search.SearchService;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.event.type.EventDispatchOption;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.Issue;

import com.atlassian.jira.issue.IssueManager;

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.history.ChangeItemBean;

import com.atlassian.jira.issue.index.IssueIndexingService;

import com.atlassian.jira.issue.link.IssueLinkManager;

import com.atlassian.jira.issue.search.SearchException;

import com.atlassian.jira.issue.search.SearchResults;

import com.atlassian.jira.security.groups.GroupManager;

import com.atlassian.jira.user.ApplicationUser;

import com.atlassian.jira.web.bean.PagerFilter;

import com.atlassian.query.Query;

import com.google.common.base.Strings;

 

String jqlQuery = "YOUR_JQL_HERE";

String scriptResult = "";

 

final SearchService searchService = ComponentAccessor.getComponent(SearchService.class);

final IssueManager issueManager = ComponentAccessor.getIssueManager();

final CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

final IssueIndexingService issueIndexingService = ComponentAccessor.getComponentOfType(IssueIndexingService.class);

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

 

 

//RETRIEVE ISSUES

final List<Issue> issueResult= new ArrayList();

if(!Strings.isNullOrEmpty(jqlQuery)){

final SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);

final Query query = parseResult.getQuery();

try {

final SearchResults<Issue> result = searchService.search(user, query, PagerFilter.getUnlimitedFilter());

final List<Issue> issues = result.getResults();

for(final Issue issue : issues){

issueResult.add(issueManager.getIssueObject(issue.getId()));

}

 

} catch (final SearchException e) {

}

}

int total = 0 ,updated = 0;

for(Issue is : issueResult){

total ++;

List<Group> visibilityGroups = new ArrayList<Group>();

MutableIssue mIssue = (MutableIssue) is;

try {

if(!is.getAssigneeUser().isActive()) {

mIssue.setAssignee(mIssue.getProjectObject().getProjectLead());

Issue issue = issueManager.updateIssue(user, mIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

issueIndexingService.reIndex(issue);

updated++;

}

} catch (Exception e) {

e.printStackTrace();

}

}

long endTime =System.currentTimeMillis();

return "Total : "+total+" - Updated :"+updated;

}

Hope this helps,

Fabio

DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events