Forums

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

Default Values for fields on transition screen - ScriptRunner

Tobias
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.
November 2, 2022

Hello all,
I am currently trying to find a solution to provide default values for fields on transition screens. The default ones that can be set in the field context are only taken into the create issue screen.

We have ScriptRunner in use and I have also already reviewed the following documentation: Setting Field Defaults 

 

However, I have not yet found a solution for fields on transition screens. I would like to set a default value to give the customer a template for filling the field.

Is there a possibility to realize this in ScriptRunner.

Thanks a lot!
Greetings
Tobi

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Vikrant Yadav
Community Champion
November 2, 2022

Hi @Tobias For adding Default value on Transition screen, you have to create Scriptrunner Behaviour of this and Limit behavior only to that Transition screen. Kindly check this document :- 

https://library.adaptavist.com/entity/limit-a-behaviour-to-a-specific-screen-in-jira

Thanks

V.Y

Tobias
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.
November 4, 2022

Hi @Vikrant Yadav thank you for your answer. Looks like this is what I am searching for. How about the definiton of the variables. Is there the visual field name required or the technical customfield ID, what about the screen name? 

Below the result of my first test, not working. Mapping is added. 

 

import groovy.transform.BaseScript

import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

final String screenName = 'Testing XY'

final String fieldName = 'customField_15720'

final String expectedValue = '||Use-Case|Coasts||'

if (fieldScreen.name == screenName) {

    def field = getFieldByName(fieldName)

    field.value == expectedValue ? field.clearError() : field.setError('This is not a valid value')

}

Vikrant Yadav
Community Champion
November 5, 2022

Hi @Tobias  Variable you can define as per the field name, if the field name is Application, you can create variable with name application. If you are trying to set default for select list field on a transition screen, you can use below script, replace bold value with your value  :- 

 

import groovy.transform.BaseScript

import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

final String screenName = 'VTP Resolve Issue Screen' //add transition screen name

def application = getFieldByName("Application Count")//add field name of which you want set default value

def optionsManager = ComponentAccessor.getOptionsManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def customField = customFieldManager.getCustomFieldObject(application.getFieldId())

def config = customField.getRelevantConfig(getIssueContext())

def options = optionsManager.getOptions(config)

def optionToSelect = options.find { it.value == "3" } //put the value which you want to set default

if (fieldScreen.name == screenName){

application.setFormValue(optionToSelect.optionId)

}
Like Petr Michna _EXT_ likes this
0 votes
Aleksandra Bosacka _Deviniti_
Atlassian Partner
November 7, 2022

Hi @Tobias 

 If you don’t mind using a plugin, I believe that as an alternative to a default value defined with ScriptRunner and Behaviours, you could also use our Issue Templates for Jira  app to automatically apply predefined values into custom fields once the issue transitions through the workflow.

In short, the app allows you to create a repository of reusable templates for all different types and populate selected issue fields automatically with a value defined in the template. Such a template can be also set as default for a specific transition, and thanks to that it will be automatically applied to chosen issue types and screens in a project.

For more details, I encourage you to see this chapter in our online documentation: Default templates  I hope you will find it useful!

Feel free to reach out or reply directly in this thread for more details. I will be happy to help!

Cheers,
Aleksandra

TAGS
AUG Leaders

Atlassian Community Events