Copy custom field value.

Adolfo satdp May 14, 2022

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

3 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 16, 2022

 

If you want to copy the value of one field to another field during a transition, ScriptRunner's Behaviour is the best option.

 

ScriptRunner's Behaviour works on the Create / Edit / Transition and also Assign issue screen. You can refer to this ScriptRunner documentation for more information.

 

To filter the group picker based on the list selection, you can try something like:-
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:-

behaviour_config-1.png

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:-

test1.png

2) If Option2 is selected from the List, the Group field is updated to jira-software-users as shown below:-

test2.png

3) If Option3 is selected from the List, the Group field is updated to jira-servicedesk-users as shown below:-

test3.png

I hope this helps to solve your question. :)

Thank you and Kind regards,

Ram 

 

 

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2022

Hi @Adolfo satdp ,

do you need to do that in the screen (during creation, edit or transition screen) or in apost function?

Adolfo satdp May 15, 2022

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).

Adolfo satdp May 15, 2022

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.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2022

Hi @Adolfo satdp ,

post function is something that happens after the transition execution so you can't popup a screen

Adolfo satdp May 15, 2022

Hi @Fabio Racobaldo _Herzum_ 

Yeah, the screen with custom field select list, pop up during transition. So I need that, in postfunction, happen the change.

0 votes
Ivan Lima
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.
May 14, 2022

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:

Adolfo satdp May 15, 2022

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events