is it possible make default value of select issue filed when issue changes status and popup screen coming up?I tried it in behaviours ... but it doesn`t work
Hi @Виктория
If you intend to set the default value for the list, a sample code is available in the Adaptavist Library.
Below is the sample code for your reference:-
import com.atlassian.jira.component.ComponentAccessorimport com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours fieldBehaviours// a single select list custom field namefinal String fieldName = "Select List"// the value to setfinal String setValue = "Some Value"def field = getFieldByName(fieldName)def optionsManager = ComponentAccessor.optionsManagerdef customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issueContext.projectId, issueContext.issueTypeId).find { it.name == fieldName}assert customField : "Could not find custom field with name $fieldName"def fieldConfig = customField.getRelevantConfig(issueContext)def options = optionsManager.getOptions(fieldConfig)def option = options.find { it.value == setValue }assert option : "Could not find option with value $setValue"field.setFormValue(option.optionId)
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Please also note this should be done using the Behaviour Initialiser.
To do this via Server-Side Behaviour, you must not initialise the field using the Field Name. Instead, it would be best if you declare it as:-
def field = getFieldById(fieldChanged)
This ensures that the Behaviour will only take effect if you have made any changes to that field the Server-Side Behaviour has been configured for.
But since you want to set the default value when the Create or Edit screen is loaded, the Behaviour Initialiser is the best approach.
I hope this helps answer your question. :-)
Thank you and Kind regards,Ram
Hi @Виктория ,
Seems to me that you are using Adaptavist ScriptRunner ( Please mention the other name if it's not)
So if yes you need to create a ScriptRunner behaviour.
I can help you with the steps, if you want help with this let me know.
Regards
Oday
@Oday Rafeh that is write.help please
Okay fine @Виктория
The correct approach to set a default value for the 'Development type' custom field during a transition:
import com.atlassian.jira.component.ComponentAccessordef customFieldManager = ComponentAccessor.getCustomFieldManager()def developmentTypeField = getFieldByName("Development type")// Replace 'Low Code' with the default value you want to setdef defaultValue = "Low Code"if (developmentTypeField.getValue() == null) {developmentTypeField.setFormValue(defaultValue)}
Save the script and behaviour.
Let me know if this helped.
@Oday Rafeh you lost issue status,i need it in poop up window when transit from status "design"you example do it like always when issue create i need this field empty
@Ram Kumar Aravindakshan _Adaptavist_ you lost issue status,i need it in poop up window when transit from status "design"you example do it like always when issue create i need this field empty
Thank you for providing the clarification.
If you intend to set the value for the Multi-Select List on a Transition Screen, all you have to do is:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef multiSelect = getFieldByName('Sample Multi List')if (actionName == 'In Progress') { multiSelect.setFormValue(['Sample 1'])}
Please note that the sample code above is not 100% exact to your environment. Hence you will need to modify it accordingly.
Before adding the code above, it would be best to do basic logging to determine the action name. You will need to add the logging below:-
log.warn "============>>> ${actionName}"
In my environment, the actionName returns In Progress. Hence, I am using 'In Progress' in the if/else condition shown in the code above.
You must use the Behaviour Initialiser when using the code above for it to work as expected.
Below is a screenshot of the Behaviour configuration:-
Below is a screenshot of the workflow that I am testing with:-
I am also including a couple of these screenshots for your reference:-
1. First, I create a sample issue of Bug-type as shown in the image below:-
2. Next, I transition the issue to In Progress, as shown in the image below:-
3. When the transition takes place, the dialog pops up, and in it, the Multi-Select List has been set to the default value Sample 1, as expected.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_
like this it doesn`t workI do use the Behaviour Initialiser
where in code i need to put this ?
log.warn "============>>> ${Design}"
@Oday Rafeh
this works! thank you
Greate, very happy to hear that
@Ram Kumar Aravindakshan _Adaptavist_ can we update code and make a check if field is empty?
To answer your question, yes you can. You can include an if/else check like:-
multiSelect.clearError()if (!multiSelect.value) { multiSelect.setError('Value has not been set')}
Below is the updated sample code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef multiSelect = getFieldByName('Sample Multi List')multiSelect.clearError()if (actionName == 'In Progress') { multiSelect.setFormValue(['Sample 1'])} if (!multiSelect.value) { multiSelect.setError('Value hoas not been set')}
I just need to check that
Sample Multi List
has not beet set before, if it already has a value then to do nothing.rules above not really works
If you want to check whether the field has already been set, then you will need to use
if (multiSelect.value) { return}
Your updated code should be like this:-
import com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScript@BaseScript FieldBehaviours behavioursdef multiSelect = getFieldByName('Sample Multi List')if (multiSelect.value) { return}if (actionName == 'In Progress') { multiSelect.setFormValue(['Sample 1'])}
So if the multi-select field already has a value set for it, it will ignore it and not do anything.
I hope this helps to solve your question. :-)Thank you and Kind regards,
It looks like you're new here. Sign in or register to get started.