fast track transition issue based on user picker field

David B February 10, 2016

I'm trying to fast track a transition an issue based on a user picker having a value or not.

If the user picker is populated I want the transition to fire. If it's empty I don't.

Without any example for referencing a user picker I had a few guesses but no matter what I tried the transition would never occur. There was nothing in the logs so as far as I can tell there is no actual error.

 

What is the correct syntax for determining if a user picker has a value?

 

3 answers

1 accepted

0 votes
Answer accepted
Fidel Castro
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 can also do it using "Set field as a function of other fields" post-function of JIRA Workflow Toolbox plugin as I show in the screenshot:

Captura de pantalla 2016-02-12 a las 12.51.44.png

In this case transition "Assign Issue" will be executed if custom field "User Picker" hasn't a value, and transition "Start Progress" if the field is set.

Note that ^$ is regular expression for empty string, and .* is regular expression for a non-empty string.

0 votes
David B February 11, 2016

I figured it out after looking through the source code for script runner and doing some tests in script console.

The null conditions are as simple as

cfValues['User Picker'] == null // to check for empty
or
cfValues['User Picker'] != null // to check for populated

 

also cfValues['User Picker']?.toString() resolves to "TestUser(testuser)" (for a user called testuser) when populated and "null" when not populated.

With this syntax it could be used to check for a specific user.

 

0 votes
Vasiliy Zverev
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 10, 2016
  1. Get object for custom field like that:

    CustomField cstFld_getTime = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customFieldName")
  2. Get value for sertain issue and check for null

    if(issue.getCustomFieldValue(cstFld) == null){
    //	actions if null
    }
    else{
    	//actions if not null
    }

 

 

David B February 10, 2016

Are you saying that I cannot use the script post function to do it and can only do it in a groovy script? If that's the case then I'm going to have to learn how to transition an issue in groovy.

Vasiliy Zverev
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 10, 2016

You can use Script postFunction provided ScriptRunner plugin

David B February 10, 2016

Yes but I would like to use "Fast-track transition an issue" which really isn't compatible with what you've posted.

What you've posted is more suited to  "Custom script post-function" which i'm hoping to avoid as I need to learn a whole lot more than just how to access a custom user picker.

Also i'm not sold on what you've posted working for a user picker anyway seeing as it's not just a simple field but an object.

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events