How to auto populate custom field(text) based on another custom field(checkbox) using script runner

anil musunuru December 21, 2018

I have a Custom field(checkbox field) Fruits with values Apples,Oranges,Lemon.

I have another Custom field(Text field) Shop,

When Apples is checked then i need to auto populate Shop custom field with value (TechDev)

When Oranges is checked then i need to auto populate Shop custom field with value (TechArch)

This is in a view/edit screen so i am looking for script listeners to do the job

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -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.
December 22, 2018

I think we need to clarify the requirement first.

"Auto populate" is usually used to mean "when a field is presented to the user for them to put data in it, fill it in for them, with a suggested value, but let them continue to put what they actually want in the field if they don't like the suggestion".  There is an often unstated assumption that if you're in an edit, you do not overwrite the current value (Mostly because that would *really* annoy your users, having to re-enter the current value on every edit)

But, you mention listeners, which leads me to the second possible meaning, which is that you don't want the users to be able to over-ride the pre-populated value, you just want to set the value based on data on the issue at a certain point in the lifecycle. (A second question in this case is whether you ever want them to be able to edit the value)

So, three options:

  • If you want to pre-populate, but allow the user to override a value on the create or edit, you need a Behaviour
  • If you want to set a value after they commit their data on create or transition, and allow them to change it later, then you need a listener or post-function
  • If you want to calculate a value that the user cannot change, a scripted field might be a better choice (scripted fields let us down when we want select-type fields that are searchable)
anil musunuru December 22, 2018

Thanks for your time, i am looking for option 2 with a listener.

Like Nic Brough -Adaptavist- likes this
Nic Brough -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.
December 22, 2018

The standard script for that is at https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-using-a-listener   You will need to write an "if then" bit for checking the value of the radio button.

anil musunuru December 22, 2018

link you provided opens up with a 404 error  @Nic Brough -Adaptavist-

Like Nic Brough -Adaptavist- likes this
Nic Brough -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.
December 22, 2018

Bother.  Sorry.  Lithium does that sometimes - it has padded the end of the url with control characters.  Either copy and paste the visible text of the url, or go to it again and edit the url to remove the %A32 type bits on the end of it.

Sekhar Chandra September 16, 2019

@Nic Brough -Adaptavist- 

Can't be the option 1 done without using scripts?

Please let me know if there is any other alternative for this.

 

Thanks.

Nic Brough -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.
September 16, 2019

No, you need code to do this.

Radhika Suresh January 24, 2021

Hello Nic, In my use case, I'd like to capture "Fix Version History" in a separate custom field that allows multiple selections. This enables me to see how many times a particular issue was opened and re-opened for enhancements or bug fixes. How can I pre-populate the drop-down list for this custom field from the release versions that JIRA already maintains?

Nic Brough -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.
January 24, 2021

I would not do it that way at all.  The history captures all changes, and you should be reporting off that really.  Also, a multi-select field would not capture open/reopen if it happened more than once.  I'd be looking to script a scripted-field for this, one that can read the history and display all the data you need.

Samyak Masulkar October 25, 2021

is this option available in jira cloud ?

1 vote
Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 21, 2018

Hi @anil musunuru,

As you mentioned ScriptRunner, did you think about Behaviours? 

Populating fields depending on other fields is working pretty good with this. But you loose inline editing capabilities .

anil musunuru December 21, 2018

Exactly,Thats the reason why i am looking for script listener to do it

Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 21, 2018

@Nic Brough -Adaptavist- do you have any ideas on this or know someone who does?

Like Nic Brough -Adaptavist- likes this

Suggest an answer

Log in or Sign up to answer