Update the resolution field in issue on workflow transition

hemanth acharya September 18, 2014

Hi all,

There are two customized workflows defined at the moment. There is a postFunction defined for each of the workflows separately. But, there is a scenario when the transition can happen from one state of workflow1 to another state of workflow2. We cannot set a postfunction for such a transition, but it should happen such that on this particular transition the resolution has to be set to "None". I have to do this in the code itself. Right now am trying with some groovy scripts but it seem not to work, can anyone help me on this scenario.

I had the following groovy which is not serving the purpose. Could anyone please help me?

import com.atlassian.jira.issue.IssueManager;
			import com.atlassian.jira.issue.MutableIssue;
			import com.atlassian.jira.project.Project;
			import com.atlassian.jira.project.ProjectManager;
			import com.atlassian.jira.issue.issuetype.IssueType;
			import com.atlassian.jira.workflow.JiraWorkflow;
			import com.atlassian.jira.component.ComponentAccessor;
			import com.opensymphony.workflow.loader.ActionDescriptor;
			import com.opensymphony.workflow.loader.FunctionDescriptor;
			import webwork.dispatcher.ActionResult;
			import com.atlassian.core.util.map.EasyMap;
			import com.atlassian.core.ofbiz.CoreFactory;
			import com.atlassian.jira.ComponentManager;
			
					
			
			IssueManager issueManager = ComponentAccessor.getIssueManager();
            MutableIssue targetIssue = issueManager.getIssueObject("ALM-1696");
		          ProjectManager projectManager =ComponentAccessor.getProjectManager();
            
              String tartgetProject=targetIssue.getProjectObject().getKey();
          Project targetProject = projectManager.getProjectObjByKey(tartgetProject);
		  
		            IssueType issueTypeObject=null;
					def issueType = "Bug"
					def Status = "Code/Hardware Bug (Response/Resolution)"
          
             Collection<IssueType> issueTypes=   ComponentAccessor.getIssueTypeSchemeManager().getIssueTypesForProject(targetProject);
             Iterator itr=issueTypes.iterator();
			//	ComponentManager componentManager = ComponentManager.getInstance()
             //  User remoteUser = componentManager.getJiraAuthenticationContext().getUser() 
             while(itr.hasNext()){
                 IssueType projectIssueType=(IssueType)itr.next();
                 if(issueType.equals(projectIssueType.getName()))
                 {issueTypeObject=projectIssueType;
                  break;} 
                 }
		  
		   JiraWorkflow workflow=ComponentAccessor.getWorkflowManager().getWorkflow(targetProject.getId(), issueTypeObject.getId());
		   
		   Collection<ActionDescriptor> actions = workflow.getAllActions();
		   authenticationContext =ComponentAccessor.getJiraAuthenticationContext()	
		   
		    for (final ActionDescriptor actionDescriptor : actions)
        {
            if (actionDescriptor.getName().contains(Status))
            {
             
             targetIssue.setResolution(null);
            // targetIssue.store();
			// targetIssue.update(ComponentAccessor.getUserManager().getUserObject("some email id"),targetIssue, null,false) 
               Map actionParams = EasyMap.build("issue", targetIssue.getGenericValue(), "issueObject", targetIssue, "remoteUser", ComponentAccessor.getUserManager().getUserObject("some email id"), "dispatchEvent", Boolean.FALSE);
               ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.ISSUE_UPDATE, actionParams); 
                
            }
        }

 

Thanks,

Hemanth

1 answer

1 accepted

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
September 18, 2014

Use IssueTransition validateTransition and transition methods. You can set the resolution in IssueInputParameters.

hemanth acharya September 21, 2014

Could you please provide me with a snippet?

Jobin Kuruvilla [Adaptavist]
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.
September 21, 2014

If you search for samples in this forum or in google, you will find quite a few ;)

hemanth acharya September 23, 2014

I don't know why I typed that comment :P Was too lazy I guess to search. Got it thanks. :)

Suggest an answer

Log in or Sign up to answer