Script Runner Condition to Show Specific Screen

DerivcoITServer January 18, 2017

Hi,

I am using the script runner plugin to clone an issue to a specific project based on the value of a custom field.

By using a transition screen I can allow the user to enter new mandatory parameters required to create the issue in the new project. All statuses can transition to this status.

I can specify a transition screen in my workflow but this will mean the same screen will be shown all the time.

How can show different transition screens based on the value of my custom field? So that a new transition screen can be shown to create an issue for different projects.

4 answers

1 accepted

3 votes
Answer accepted
Jonny Carter
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.
January 18, 2017

You can use Behaviours to modify the visible/required fields on a screen. You can use a scripted transition to limit the behaviour to a particular workflow step, so that it's only applied on the relevant transition screen. You could add an initialization script to a behaviour with something like

if (getActionName() == "Transfer Ownership") {
    def fieldToHide = getFieldByName("Some custom field I wish to hide")
    def fieldToRequire = getFieldByName("Some custom field I wish to require")
    fieldToHide.setHidden(true)
    fieldToRequire.setRequired(true)
}

Notably, that would require you to add to the workflow transition screen. If you only wanted that field to show up for that particular transition (and no other transitions), you could do something like:

def fieldsThatOnlyShowOnSomeTransition = ["Field A", "Field B", "Field C"]
fieldsThatOnlyShowOnSomeTransition.each{ fieldName ->
    boolean includeFieldX = getActionName() == "Start Progress"
    def fieldX = getFieldByName(fieldName)
    fieldX.setHidden(includeFieldX)
}

Which can be a little more readable and maintainable for a large number of fields. It's also easier to adjust if the parameters that determine whether a given field should show are more complex than simply "Are we in some particular workflow step?"

DerivcoITServer January 19, 2017

Thanks. I am currently implementing this recommendation.

I have run into one stumbling block thus far.  In the Initializer function, I can get the object of one of my custom field that is of a Group Picker (Single) type using getFieldByName, but when i call getValue() on the object I get a null value.

 

The same function works fine if I add a field with a validation script. It seems like when the initializer script is executed the value is not yet populated.

Jonny Carter
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.
January 19, 2017

Initializer scripts are always run as soon as the page is loaded, and are only run once. If that field is empty when the page is run, you should expect its value to be null when the initializer runs.

If you need a script to run every time a particular field changes, then it needs to be associated with that field. For some cases, you may need to examine a particular field in both an initializer and in a validation script on that field (or even on some other field). It just depends on what you're trying to do with that script.

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.
January 20, 2017

That's not quite the case... no values are available in an initialiser whether set or not. You can get the value of any CF using the regular java api, getUnderlyingIssue() will give you the regular Issue object, then use issue.getCustomFieldValue

Eric Monfette November 19, 2019

Could anyone please confirm if this method works still and send a copy of their script. Mine is not working for workflow function.

M Vijay Kumar April 23, 2020

Hi all,

 

I am trying to achieve same thing. I would like get a transition screen when I move my user story from Status A (backlog)  to Status B (sprint backlog.)

Transition Screen needs user input to move to status from Status A to Status B. 

Any suggestions would be really helpful.

1 vote
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.
January 18, 2017

You could create several transitions with different transition screen. 

Add a condition on each to show for user only one at a time basedon custom field value.

DerivcoITServer January 18, 2017

We have over 20 statuses in this workflow with each status allowing all transitions from any other status enabled.

If we had to keep the same behaviour by creating individual transitions between each status, that would make the workflow really cluttered and messy.

Is there no other alternative ? Like calling a ShowScreen("ABC: Bug Screen") method from a condition ?

DerivcoITServer January 18, 2017

This is the problem I am trying to solve:

We have a project A that contains issues that Team A works on. Team A assigns these issues to various other teams using a custom field group picker, example team B.

Team B does not want to conform to project A's workflow and custom fields. They want to use their own workflow and custom fields.  

To solve this we are using the script runner clone issue post-function.  We check the value of the custom field and depending on the value we create the linked issue to the new project, example project B that team B works on.  Project B requires additional information when creating issues, Team A knows this information, so they need to fill these in when assigning the ticket to Team B.

Depending on the team that Team A assigns the issues to, the issues will need to be created on a new project showing different screens.

0 votes
Nombulelo Zizi October 3, 2017

Good day,

 

I'm using the same code and nothing is happening

 

 

Below is my code and it's not doing anything.

 

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldById("customfield_10306")
FormField fconditionA = getFieldById("customfield_10510")
FormField conditionB = getFieldById("customfield_10515")

if (dropDownValue.getFormValue() == "High")

conditionA.setHidden(false)
conditionB.setHidden(true)

}
else
{
f conditionA.setHidden(true)
conditionB.setHidden(false)
}

 

Jira Service Desk 3.6.1

ScriptRunner 5.1.6

0 votes
Nombulelo Zizi October 3, 2017

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldById("customfield_10306")
FormField fconditionA = getFieldById("customfield_10510")
FormField conditionB = getFieldById("customfield_10515")

if (dropDownValue.getFormValue() == "High")

{ //Yes

conditionA.setHidden(false)
conditionB.setHidden(true)

}
else
{
f conditionA.setHidden(true)
conditionB.setHidden(false)
}

Suggest an answer

Log in or Sign up to answer