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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
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