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
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
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')
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.