Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How does the Script Runner - Script workflow function : Fast-track transition an issue works?

Pierre Gourven February 11, 2016

When I create an issue, I want to transition it to the state I want programmatically.
I work on JIRA 7 - JSD 3.0.3. with Script Runner 4.2.0.5
I use the Script Runner - Script workflow function : Fast-track transition an issue and let an empty condition so that it will be fired at each time and my issue is not set to the state link to the transition I fired.

I also try to do so thanks a script function but it seems that ComponentManager.getInstance().getIssueService() is not supported anymore.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
MutableIssue issue = issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
// Mise à jour du champ TEST_MAJ_SCRIPT_RUNNER champ texte simple
issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName("TEST_MAJ_SCRIPT_RUNNER"), "TOTO");
custom_field = customFieldManager.getCustomFieldObjectByName("TECHNOLOGIE");                
fieldval = issue.getCustomFieldValue(custom_field);
    
// Gestionnaire de groupe
groupManager = ComponentAccessor.getGroupManager();
//group = groupManager.getGroup("+ ZT_DEL_N3_Datastage");
log.debug "Valeur du test config:" + fieldval
switch(fieldval)
{    
case "Réalisation Teradata":    
group = groupManager.getGroup("+ ZT_DTA_N3_TD");    
break;    
case "Réalisation OTIC":
group = groupManager.getGroup("+ ZT_DTA_N3_Genio");        
break;        
case "Réalisation SAS":
group = groupManager.getGroup("+ ZT_DTA_N3_SAS");        
break;    
case "Réalisation Cognos BI":
group = groupManager.getGroup("+ ZT_DTA_N3_Cognos");    
break;   
case "Réalisation QlikView":
group = groupManager.getGroup("+ ZT_DEL_N3_Qlikview");    
break;    
case "Réalisation Birt":
group = groupManager.getGroup("+ ZT_DEL_N3_Birt");  
break;    
case "Réalisation Datastage":
group = groupManager.getGroup("+ ZT_DEL_N3_Datastage");        
break;    
default:
group = "";    
}
log.debug "Valeur de group:" + group
// Recherche du champ TEST_GROUPE_SCRIPT_RUNNER
custom_field = customFieldManager.getCustomFieldObjectByName("TEST_GROUPE_SCRIPT_RUNNER");                
// Mise à jour du champ
if (group != "")
{
issue.setCustomFieldValue(custom_field,[group]);
}
def issueService = ComponentManager.getInstance().getIssueService();
issueInputParameters = issueService.newIssueInputParameters(); 
// Exécution de la transition vers 
user = issue.getReporter();
TransitionValidationResult validationResult = issueService.validateTransition(user, issue.getId(), 761, issueInputParameters);
// 2 is the Close Issue transition ID
issueService.transition(user, validationResult);

 


Thanks for your help

Pierre

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2016

If you want it to always fire, why not just change the workflow so that the state you are 'fast tracking' into is the destination of the Create transition?

As far as your post function goes, try changing the condition to something that explicitly evaluates to 'true'.

Pierre Gourven February 11, 2016

Thanks for your comment Jeremy. I just try an Hello World! post function because with other conditions it does not work and it is written in the documentation that empty condition is considered as true. But it does not work.

Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2016

Other thoughts are:

1) Did you make certain you selected the specific transition in your workflow from Create -> Destination, with the matching transition ID?

2) Did you put the fast-track post function at the end of the post function list?

Pierre Gourven February 11, 2016

How can I be sure of my transition ID. I took the one displayed on my workflow text (see attach printscreen 2).
My workflow look like this.
When my customer create a ticket, he choses a topic, depending on this topic I want to trigger one transition or an other.
So my post function is put on my create issue transition and I want to trigger Traiter cette demande.
20160211_Capture_workflow_diagram.JPG
20160211_Capture_Workflow.JPG

Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2016

Yes, 801 looks to be the correct ID.  If that's what you selected for your 'fast track' on Create Issue, and it fires after all of the other post functions (emit an event, etc), then it seems like it should be working.

I assume that transition has no screen?

Pierre Gourven February 12, 2016

What might be the problem with screen?

Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2016

If the transition has a screen, it's conceivable that the fast track would fail because it requires user input, especially if the transition also has a validator requiring one of the fields to be entered.  I haven't tested that case, I'm just thinking out loud; I do know, however, that the only time I've used this, the transition was screen-less.

Pierre Gourven February 12, 2016

I often get this kind of error message
2016-02-12 18:14:32,840 http-nio-8080-exec-19 ERROR INUGOUP 1094x7598x1 1usokj4 20.10.6.16 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.common.StaticCompilationChecker [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: Could not initialize class com.onresolve.scriptrunner.runner.stc.ScriptCompileContext$ContextByName

Pierre Gourven February 12, 2016

What is strange is that I have some workflow that are inactive and even though I select 761 transition for my active workflow, when I edit the step it's the step from the inactive one which is used

20160201_Workflow_Capture.JPG

The result of the function is said to be a success but my ticket still have the same State.

20160212_Capture.JPG

Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2016

You need to select 801; 761 is from the state "COMPLEMENT_CLIENT", not "DEMANDE_A_TRAITER".  Since DEMANDE_A_TRAITER is the destination state for the "Create Issue" transition, that is the start state of the fast-track operation.

Pierre Gourven February 15, 2016

Hi Jeremy,

I eventually get the result I expected.
I put the Script workflow function : Fast-track transition an issue as the last operation on my transition.
I added some triggering conditions with the following syntax.

cfValues['Thème']?.value == 'Réalisation Teradata'  ||
cfValues['Thème']?.value == 'Réalisation OTIC'      ||
cfValues['Thème']?.value == 'Réalisation SAS' 

Thanks a  lot for your help

Pierre

1 vote
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2016

Hi Pierre

Here is an example of a transition using ComponentAccessor

def issueService = ComponentAccessor.getIssueService()
def applicationUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def validationResult =
        issueService.validateTransition(applicationUser, issue.id, actionId, new IssueInputParametersImpl())

if(validationResult.isValid()) {
    def transResult = issueService.transition(applicationUser, validationResult)
    if (transResult.isValid()) {
        log.debug("Transitioned issue $issue through action $actionId")
    } else {
        log.debug("Transition result is not valid")
    }
} else {
    log.debug("validation result not valid")
}

Hope that helps.

Kind regards

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2016

See https://scriptrunner.adaptavist.com/latest/jira/releases/release-4.1.4.html for this and other changes you may need to make.

Pierre Gourven February 15, 2016

Thanks a lot guys

TAGS
AUG Leaders

Atlassian Community Events