Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Copy option values from one custom field to another

Hi,

I have 2 custom fields - one select choice and one multiple choice.

I would like to do this flow:

1. Insert a new option in the first custom field (select choice).

2. The second custom field (multiple choice) will insert automatically the same option.

 

I try to do it with script listener, but without success.

 

I try this code:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.IssueManager

Issue issue = event.getIssue();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def optionsManager = ComponentAccessor.getComponentOfType(OptionsManager.class);

//Get Options values of "WBL Agile Team"
def wblTeam = customFieldManager.getCustomFieldObjectByName("WBL Agile Team");
def fieldConfig1 = wblTeam.getRelevantConfig(issue);


def options1 = optionsManager.getOptions(fieldConfig1);
def results1=[];
def i=0;
for (Option option1 : options1) {
results1[i]=option1.value;
i++;
}

//Get Options values of "WBL Agile Team/s"
def wblTeams = customFieldManager.getCustomFieldObjectByName("WBL Agile Team/s");
def fieldConfig2 = wblTeams.getRelevantConfig(issue);
def options2 = optionsManager.getOptions(fieldConfig2);
i=0;
for (Option option2 : options2) {
option2.Value=results1[i];
i++;
}

 

Thanks,

Daniel

1 answer

Hey Daniel, 

The following script will append to the multi select list the value of the single select list. 

This should be a custom listener, listening for an issue updated event. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issue = issue as MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "SelectListA"}

// if is not the SelectListA that got updated, do nothing
if (!change) { return }

def customFieldManager = ComponentAccessor.customFieldManager
def selectList = customFieldManager.getCustomFieldObjects(issue).find {it.name == "SelectListA"}

def selectLitValue = issue.getCustomFieldValue(selectList) as LazyLoadedOption

if (!selectLitValue) {
return
}

def multiList = customFieldManager.getCustomFieldObjects(issue).find {it.name == "MultiSelectA"}
def oldValues = (issue.getCustomFieldValue(multiList) as List<LazyLoadedOption>) ?: []

def changeHolder = new DefaultIssueChangeHolder()
multiList.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(multiList), oldValues << selectLitValue), changeHolder)

Please let me know if this does the trick for you.

Regards, Thanos

Hi,

Thank you,

It isn't help.. the options didn't change

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

62 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you