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
thank you for your help
I'm really sorry for not replying to you in time. The code you provided has resolved our issue. Thank you once again for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for your apply
I apologize for the delayed response. The code you provided has been very useful to us, and we appreciate your help. However, we would like to further optimize it. May I assign it to the corresponding module leader? I tried using your method to obtain the module information, but it doesn't seem to be supported. Could you please advise on how to optimize it? Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes,I would like to assign the issues of inactive users to the corresponding component leads.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@arno ,
this script will assign issues assigned to incative user to the first component lead
{code}
{code}
Hope this helps,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.