Hello there!
For some reasons, I use the migrateIssueToWorkflow() function from WorkflowManager in post-functions.
Unfortunately, the transition is not written in "transition history" tab.
And when I use history in EazyBi, the transition is not existing so the statistics are all bad.
I would like to fix all my issues... Do you know a way to add an item in transition history tab?
I tried with changeItemBean but it is not the same thing... it doesn't work.
Thank you very much!
Olivier
Could you please share your current code and configuration so I can review it and provide some feedback?
Thank you and Kind regards,
Ram
Hello @Ram Kumar Aravindakshan _Adaptavist_ ,
Sorry for the delay, i was in Holliday..
We use Jira v8.5.19 and ScriptRunner 6.53.0.
Here is my script, inspired by a script developed by Kevin Bouman:
/*****************************
Purpose: This script is used to change the status of issues regardless of were they are in the workflow. No transition is needed to move an issue into another status. However, The destination status has to reside in the workflow.
Author: Kevin Bouman
Date: 08/06/2019
Updated: 12/26/2020 Kevin Bouman (Added instructions for updating the resolutions)
*****************************/
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.config.ConstantsManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.util.ImportUtils;
import groovy.time.TimeCategory
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.util.IssueUpdateBean
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.history.ChangeLogUtils
def searchService = ComponentAccessor.getComponent(SearchService.class);
def issueManager = ComponentAccessor.getIssueManager();
def constantsManager = ComponentAccessor.getConstantsManager();
def userManager = ComponentAccessor.getUserManager()
//********************** VARIABLES ******************************
//Place the name of the Destination status
def destinationStatusNames = ["créée", "a qualifier", "assessment", "en conception", "validation comar", "pi planning", "en développement", "uat en cours", "mise en production", "fermée"];
String destinationStatusName = ""
//Get the current user
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
def user = authContext.getLoggedInUser();
//Results array
def results = [];
// Get History
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHistory = changeHistoryManager.getChangeItemsForField(issue, 'status')
def changeAssigneeHistory = changeHistoryManager.getChangeItemsForField(issue, 'assignee')
def dateDernierChangement
def nouveauResponsable = null
if (!changeAssigneeHistory.isEmpty()) nouveauResponsable = changeAssigneeHistory?.first()?.from
else nouveauResponsable = user.getKey()
def currentStatus = issue.getStatus()
def currentStatusName = issue.getStatus().getName();
destinationStatusName = getPrevious(destinationStatusNames, currentStatusName.toString().toLowerCase())
if (destinationStatusName == "") return;
log.debug "On détecte le statut cible en "+getPrevious(destinationStatusNames, currentStatusName.toString())
//Get the workflow
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
def workflow = workflowManager.getWorkflow(issue);
def workflowName = workflow.getName();
//Create map to store return values
def issueMap = [:];
//Get Destination Status Object
def destinationStatus = constantsManager.getStatusByNameIgnoreCase(destinationStatusName);
//Migrate issue with WorkflowManager
workflowManager.migrateIssueToWorkflow(issue, workflow, destinationStatus);
List<ChangeItemBean> newChangeItemBeans = new ArrayList<>();
ChangeItemBean newChangeItemBean = new ChangeItemBean();
newChangeItemBean.setFieldType(ChangeItemBean.STATIC_FIELD);
newChangeItemBean.setField("Status");
newChangeItemBean.setFrom(currentStatus.getId().toString());
newChangeItemBean.setFromString(currentStatusName);
newChangeItemBean.setTo(destinationStatus.getId().toString());
newChangeItemBean.setToString(destinationStatusName);
newChangeItemBean.setCreated(new java.sql.Timestamp(new Date().getTime()));
newChangeItemBeans.add(newChangeItemBean);
ChangeLogUtils.createChangeGroup(user, issue, issue, newChangeItemBeans, false);
//Update the issue in the DB
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
//Add to map
issueMap.put("issue", issue.getKey());
issueMap.put("result", "The status was changed from $currentStatusName to $destinationStatusName");
//Reindex the issue
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${issue.key} ${issue.id}")
issueIndexingService.reIndex(issue);
ImportUtils.setIndexIssues(wasIndexing);
//Add map to results array
results.add(issueMap);
return results
//////////////////////////////////////////////////////////////////
public boolean containsCaseInsensitive(String s, List<String> l){
for (String string : l){
if (string.equalsIgnoreCase(s)){
return true;
}
}
return false;
}
public String getPrevious(List myList, String uid) {
int idx = myList.indexOf(uid.toLowerCase());
log.debug "uid : "+uid
log.debug "idx : "+idx
if (idx <= 0) return "";
return myList.get(idx - 1);
}
When i use this script, the current state in "Transitions" tab is wrong (and different from the state written at the beginning of the issue):
("Etat" = status, and "Etat actuel" = "Current status")
I need to fix all my issues transitions history to have correct statistics in EazyBi...
Thank you very much for your help.
Regards,
Olivier
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.