How to invocate "validateTransition" method while issue is created from an incoming email?

Hi all,

I've a question about a plugin that I am developing for my company.

In my jira environment, I've set an Incoming mail server and its relative mail handler.

When an email comes to a specific email address, an issue will be created under the project "XXX", issue type with id "1" (ticket).

I want that, if the email has a specific subject (for example "TEST"), the issue will be created and automatically closed with the comment "Closed automatically".

This is my plugin code:

 

public void execute(Map transientVars, Map args, PropertySet ps) throws InvalidInputException, WorkflowException{
		
   User adminUser = ComponentAccessor.getUserUtil().getUser("admin");
   ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(ComponentAccessor.getJiraAuthenticationContext().getUser());
		
   MutableIssue issue = (MutableIssue) transientVars.get("issue");
		
   if (issue.getKey().startsWith("XXX")) {
	if (issue.getIssueTypeId().equals("1")) {
	      if (issue.getSummary().contains("TEST")) {
					
		 List workflowEntries = ComponentAccessor.getOfBizDelegator().findByAnd("OSWorkflowEntry", FieldMap.build("id", issue.getWorkflowId()));
					
		 Iterator workflowEntriesIterator = workflowEntries.iterator();
		 while (workflowEntriesIterator.hasNext()) {
		 	GenericValue workflowEntry = (GenericValue) workflowEntriesIterator.next();
		        if (workflowEntry.getInteger("state") == null || "0".equals(workflowEntry.getInteger("state").toString())) {
			    workflowEntry.set("state", new Integer(WorkflowEntry.ACTIVATED));
			    try {
				workflowEntry.store();
			    } catch (GenericEntityException e) {
				e.printStackTrace();
			    }
		        }
		 }
		    		
		IssueService issueService = ComponentAccessor.getComponentOfType(IssueService.class);
		IssueInputParameters issueInputParameter = issueService.newIssueInputParameters();
		issueInputParameter.setComment("Closed automatically");
					
		ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(ComponentAccessor.getJiraAuthenticationContext().getUser());
			
		IssueService.TransitionValidationResult validationResult = issueService.validateTransition(adminUser, issue.getId(), 44, issueInputParameter);
					
		if (validationResult.isValid()) {
			issueService.transition(adminUser, validationResult);
		}
	      }
	}
   }
}

This plugin is a postfunction put on the workflow transition "Create", as last action (after the "fire the event")

If that type of issue, with that subject, is created by user interface, everithing works fine (issue created and automatically closed).

If this issue is created starting from the email, the issue will be created but not closed.

Anyone knows what's the problem?

Thanks in advance,

Stefano De Gaetano

0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

376 views 1 13
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot