Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,599
Community Members
 
Community Events
176
Community Groups

Copy custom field value.

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

 

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

Hi @Adolfo satdp ,

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

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

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.

Hi @Adolfo satdp ,

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

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

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

Atlassian Community Events