Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,335
Community Members
 
Community Events
165
Community Groups

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

1 answer

0 votes

Hi @Stefano De Gaetano ,

please check this article https://confluence.atlassian.com/jirakb/issue-created-through-email-does-not-have-the-expected-workflow-transitions-372605376.html

Are you sure that ticket created by email is of the correct type associated to your workflow?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

296 views 0 9
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you