I have an error message that is thrown when I try to execute a postfunction, the error message is:
org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.
You can see the error message in this screenshot:
In my code, I am using the line :
log.warn("MOUNA here 2 "+progressErrorCollection.getErrors().toString())
which is displaying a more meaninful message to the user which is: fixVersions:Fix Version/s is required. I would like to print this message instead to the user instead of org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.How can I enforce this? I have tried using UserMessageUtil.error(progressErrorCollection.getErrors().toString())
but it is not working. Anyone knows? Here is my code below:
package CombineTransitionsimport com.onresolve.scriptrunner.runner.util.UserMessageUtilimport com.atlassian.jira.issue.Issue;import org.apache.log4j.Loggerimport com.atlassian.jira.bc.issue.IssueServiceimport com.atlassian.jira.issue.Issue;import CombineTransitions.Configuration_CombineTransitionsimport com.atlassian.jira.bc.issue.IssueService.IssueResultimport com.atlassian.jira.bc.issue.IssueService.TransitionValidationResultimport com.atlassian.jira.event.type.EventDispatchOptionimport java.util.concurrent.TimeUnitimport java.util.concurrent.ScheduledExecutorServiceimport java.util.concurrent.Executorsimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.workflow.WorkflowTransitionUtilimport com.opensymphony.workflow.WorkflowContext;import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;import com.atlassian.jira.util.JiraUtils;import com.atlassian.jira.issue.MutableIssue;import com.atlassian.jira.util.ErrorCollectionimport com.atlassian.jira.workflow.WorkflowExceptiondef log1 = Logger.getLogger("atlassian-jira.log")def combineTransitionsHashMap= Configuration_CombineTransitions.getCombineTransitionsHashMap()def issueStatusTypeId = combineTransitionsHashMap["issueStatusTypeId"] as String;def transitionFromOpentoFixed = combineTransitionsHashMap["transitionFromOpentoFixed"] as Integer;def transitionFromFixedToTested = combineTransitionsHashMap["transitionFromFixedToTested"] as Integer;def transitionFromTestedToCompleted = combineTransitionsHashMap["transitionFromTestedToCompleted"] as Integer;def fixedStatusName = combineTransitionsHashMap["fixedStatusName"] as String;def testedStatusName = combineTransitionsHashMap["testedStatusName"] as String;def completedStatusName = combineTransitionsHashMap["completedStatusName"] as String;def fixedStatusId = combineTransitionsHashMap["fixedStatusId"] as String;def testedStatusId = combineTransitionsHashMap["testedStatusId"] as String;def completedStatusId = combineTransitionsHashMap["completedStatusId"] as String;if (issue.getStatus().getSimpleStatus().getId().equals(issueStatusTypeId)) { def ok = false ok=performTransition(transitionFromOpentoFixed, fixedStatusName, fixedStatusId); log.warn("MOUNA first boolean "+ok +" "+fixedStatusName) if(ok){ ok= performTransition(transitionFromFixedToTested, testedStatusName, testedStatusId); log.warn("MOUNA second boolean "+ok +" "+testedStatusName) if(ok){ ok= performTransition(transitionFromTestedToCompleted, completedStatusName, completedStatusId); log.warn("MOUNA third boolean "+ok +" "+completedStatusName) } } }def performTransition(int transitionToBeDone, String destinationStatus, String statusId ) { log.warn("MOUNA ORIGINAL STATUS "+ issue.getStatus() +"DEST STATUS "+ destinationStatus)issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id) def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() String issueKey = issue.getKey() IssueService issueService = ComponentAccessor.getIssueService() def issueInputParameters = issueService.newIssueInputParameters() issueInputParameters.setComment("Transitioning issue from status "+ issue.getStatus().getName()+" to status "+ destinationStatus );WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)workflowTransitionUtil.setIssue(issue)workflowTransitionUtil.setAction(transitionToBeDone)ErrorCollection errorCollection=workflowTransitionUtil.validate()if (errorCollection.hasAnyErrors()) { log.warn("MOUNA here 1 "+errorCollection.getErrorMessages().toString())return false; }else{ ErrorCollection progressErrorCollection=workflowTransitionUtil.progress() if(progressErrorCollection.hasAnyErrors()){ log.warn("MOUNA here 2 "+progressErrorCollection.getErrors().toString()) // throw new WorkflowException(progressErrorCollection.getErrors().toString()); UserMessageUtil.error(progressErrorCollection.getErrors().toString()) return false; }else{ return true; }} }