Update the resolution field in issue on workflow transition

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

This widget could not be displayed.

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

Could you please provide me with a snippet?

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

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 6 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

13 views 0 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you