Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Execute a transition automatically

Thomas Hardin
Contributor
June 12, 2018

Hello all,

I am trying to set logic for executing a specific transition based on specific logic in an issue. The logic hat I am working with is as follows:

  • Issue reporter
  • Issue reporter group membership
  • Requestor - This is different from the reporter as the value comes from an Insight attribute, however; the attribute value is a Jira User ID. We just needed this because of other data relational requirements for other projects.

Now, when the issue is created, we take the attribute value of the Requestor and populate a custom field (single user picker), called GTRI Username with the user ID. We then want to send the request in 1 of 2 directions, based on certain criteria:

  1. If the reporter and the requestor are the same, then take Path #1 (Transition A)
  2. Is the reporter and the requestor are NOT the same and the reporter is a member of a specific group, then take path #2 (Transition B)

I have been trying to use the JMWE Transition post function and can get the group membership to work using: 

(groupManager.getGroupNamesForUser(issue.reporter).contains("ESD Approval"))

But I cannot seem to get 2 critieria to work properly. So, I've been trying to use ScriptRunner's Fast-track transition an issue also, but have had no luck.

 

I was testing my code with the script console and it can get single scenarios to work, but can't get both so I need some help creating a script. I am open to:

  • Using JMWE post functions
  • ScriptRunner post functions
  • A complete groovy script to execute the transition (may be best option)

Here is what I have come up with:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def groupManager = ComponentAccessor.getGroupManager()
def reporter = issue.reporter.displayName
def gtriReporterField = customFieldManager.getCustomFieldObject(12935L)
def gtriReporter = issue.getCustomFieldValue(gtriReporterField).displayName

If/Then statement - 

if (groupManager.getGroupNamesForUser(issue.reporter).contains("ESD Approval"))  && (gtriReporter == reporter) {
execute Transition B
}
execute Transition A

I understand the the if/then logic will not work, but wanted to show you all what I was trying.

 

Thanks in advance.

 

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
June 12, 2018

Hi Thomas,

I'm not sure what you mean by not being able to get 2 criteria to work properly using JMWE. I assume you were using a Conditional Execution script, and you can totally combine criteria using boolean logic ("||" for "or" and ”&&" for "and", etc.)

What you could do is use 2 Transition Issue post-functions, one for each possible transition to trigger, and use Conditional Execution to select the one that should run. The code will be much simpler than writing a full ScriptRunner script.

For example, testing whether the reporter and the requester are the same is as simple as:

issue.get("reporter") == issue.get("GTRI Username")

You can also request help from Innovalog support. See http://www.innovalog.com/support

Thomas Hardin
Contributor
June 13, 2018

As luck would have it, an Adaptavist associate was attending our AUG meeting yesterday and was nice enough to steer me in the right direction. I wasn't too far off either. Based on our conversation, I just needed to set the condition statement up like this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def groupManager = ComponentAccessor.getGroupManager()
def reporter = issue.reporter.displayName
def gtriReporterField = customFieldManager.getCustomFieldObject(12935L)
def gtriReporter = issue.getCustomFieldValue(gtriReporterField).displayName

if (gtriReporter != reporter) {
if (groupManager.getGroupNamesForUser(issue.reporter).contains("ESD Approval")) {
return true;
}
}
return false;

 

This is working now! Thank you all for the assist on this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events