Hi!
I need to change the value of a custom field (group picker) based on the selection of another custom field (Select list).
I need to do it with scriptrunner, but I can´t do it.
Can someone help me??
Thanks
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def sampleGroup = getFieldByName('Sample Group')
log.warn "=====>>>>> ${actionName}"
if (actionName == 'In Progress') {
if(sampleListValue == 'Option1') {
sampleGroup.setFormValue('Developer')
} else if (sampleListValue == 'Option2') {
sampleGroup.setFormValue('jira-software-users')
} else if (sampleListValue == 'Option3') {
sampleGroup.setFormValue('jira-servicedesk-users')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
When the issue transitions, a transition screen will be displayed, and what this code does is that it checks the value selected in the Single Select List on that transition screen. If an option is selected from the Single Select list, it will update the Group picker accordingly.
If you observe in the code above, a condition if(actionName == 'In Progress') is added. This is to ensure that this Behaviour only works on a Transition screen.
To identify the correct action name that is used for the Transition screen, I have included a Logging parameter i.e.
log.warn "=====>>>>> ${actionName}"
So, you will need to view the log output for the actionName in your environment and accordingly modify the value.
Below is a print screen of the Behaviour configuration:-
I also include a few test screens for your reference:-
1) On the Transition screen, if Option1 is selected from the List, the Group field is updated to Developer as shown below:-
2) If Option2 is selected from the List, the Group field is updated to jira-software-users as shown below:-
3) If Option3 is selected from the List, the Group field is updated to jira-servicedesk-users as shown below:-
I hope this helps to solve your question. :)
Thank you and Kind regards,
Ram
Hi @Adolfo satdp ,
do you need to do that in the screen (during creation, edit or transition screen) or in apost function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello!!!
Yes, I need do this update field in a postfunction.
During the postfunction, pop up a screen to select the value of custom field (select list).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I forgot to comment that the value of the first field will be the same in the second field.
Only that first field is a select list and second field is a group picker.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Adolfo satdp ,
post function is something that happens after the transition execution so you can't popup a screen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, the screen with custom field select list, pop up during transition. So I need that, in postfunction, happen the change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Adolfo satdp; I'm sure you will find several examples in the community on how to script it using SR4J. Have you tried using the search bar on the top right to find similar posts? Also, there are a few ways you can implement it, such as behaviours or a post-function, if you want to copy it during a transition, for example.
Links that can give you some insights into that:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I think I have not explained well. What I need is that when selecting an option in the field, the value is automatically set in another field. It can't be a behavior.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.