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,414,339
Community Members
 
Community Events
170
Community Groups

Syncronize option list between 2 custom fields

Hello All,

I am using a custom field (single select) in our jira which contains the list of our plaforms.

Now I would like to have a second custom field (multi select) with the same list for another usage.

I am trying to figure out how I could keep both option list synced.

Any idea?

 

Thanks in advance.

1 comment

It's a little bit tricky because there are some considerations beyond ":

  1. There's no trigger to get hold of when an admin updates either list
  2. There is no way to stop admins from changing either list
  3. The options in each list will not be the same thing, there will be two options in the options table.  Imagine you've got an option called "London" for both fields.   You'll find the options table, if you look in the tables or global lists, contain things like field1:context1:London(id=10010) and field2:context1:London(id=11100)

Two of these are solvable:

  1. Have a scripted service that runs regularly, compares the two lists and updates
  2. Put logic in the scripts that does bi-directional updates (This may be a little tricky as if someone renames an option in one list, it's going to look like a delete and an add of a new one in the other list - there's no way to know its a rename)
  3. The third, there's nothing you can do about this, the options have to be separate entities.

So, as for the script, the main thing you'll need to use is optionsManager - see https://docs.atlassian.com/software/jira/docs/api/8.19.1/com/atlassian/jira/issue/customfields/manager/OptionsManager.html

Thank you very much for your answer.

So I managed to write this groovy script which only takes care of options added in field Cffrom and recopies it to field Cfto in case it is not present. Here is the script:

import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext

// SETTINGS
final def CffromName = "myfieldfrom"
final def CftoName = "myfieldto"
// END SETTINGS
def cfm = ComponentAccessor.getCustomFieldManager()
def om = ComponentAccessor.getOptionsManager()

def cffrom = cfm.getCustomFieldObjectsByName(CffromName).find()
assert cffrom : "Could not find custom field with name $CffromName"
def cfto = cfm.getCustomFieldObjectsByName(CftoName).find()
assert cfto : "Could not find custom field with name $CftoName"
def ffCfg = cffrom.getRelevantConfig(IssueContext.GLOBAL)
def localOptionsfrom = om.getOptions(ffCfg)
def ftCfg = cfto.getRelevantConfig(IssueContext.GLOBAL)
def localOptionsto = om.getOptions(ftCfg)

for (fromOptionValue in localOptionsfrom)
{
if (!localOptionsto.any { o -> o.value == fromOptionValue.value }) {
om.createOption(ftCfg, null, null, fromOptionValue.value)
}
}

 

Now the only remaining question is what is the best tool to execute it ? Is there an event that could trigger it, or is Custom scheduled job the best solution from your point of view?

Comment

Log in or Sign up to comment
TAGS

Atlassian Community Events