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

How to inherit parent's multiselect field values into child's multiselect field?

Laszlo Kremer
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 5, 2013

When I add the IssueInputParameters of a new subtask, I use the .addCustomFieldValue(Long,String) http://docs.atlassian.com/software/jira/docs/api/5.0/com/atlassian/jira/issue/IssueInputParameters.html#addCustomFieldValue(java.lang.Long, java.lang.String...) method. I'd like to add the parent's selected values which I can return with .getCustomFieldValue which returns a List. I can get the name of the items, but I have to enter the ID as string in the .addCustomFieldValue which is not available from the result of .getCustomFieldValue.

Is there a straightforward method of passing the parent's multiselect field values to the child's IssueinputParameters?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Laszlo Kremer
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 5, 2013

Meanwhile I found the .getOptionId() of the Option which returns the ID. The ValidationResult can be confusing as it says "Allowed values: 10100[option1], 10102[option2]" but you should only pass a String[] with the IDs.

SO the solution is:

1. get the selected values

List<Option> selectedvalues = (List<Option>) mutableIssue.getCustomFieldValue(cfProduct);

2. Iterate trough and get those IDs

List<String> selectedIDs = new ArrayList<String>();

if (selectedvalues != null)
{
	for (Option option : selectedvalues)
	{					
		selectedIDs.add(option.getOptionId().toString());			
	}
}

3.add the customfield value

createIssueInputParameters.addCustomFieldValue(cfProduct.getId(), selectedIDs.toArray(new String[selectedIDs.size()]));

That worked for me.

Manjunatha K R March 13, 2017

Hi Laszlo,

I tried to use the above groovy script in my post function to copy multiselect field values (i,e Global XLS Config Input List-1 Components) into EPIC's customfield value.

But Unable to get it updated into EPIC's custom field. Is my missing something in this script???

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
log.setLevel(org.apache.log4j.Level.DEBUG)
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.customfields.option.Option

def issue = issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.getIssueService()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def epicLink = issue.getCustomFieldValue(epicLinkCf) as Issue
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

def cascade6 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Global XLS Config Input List-1 Components")

    List<Option> selectedvalues = (List<Option>) epicLink.getCustomFieldValue(cascade6);
    
    List<String> selectedIDs = new ArrayList<String>();
 
    if (selectedvalues != null)
    {
        for (Option option : selectedvalues)
        {                  
            selectedIDs.add(option.getOptionId().toString());          
        }
    }
   
  
    
issueInputParameters.addCustomFieldValue("customfield_10708", selectedIDs.toArray(new String[selectedIDs.size()]))

def updateValidationResult = issueService.validateUpdate(currentUser, epicLink.id, issueInputParameters)
 
    if (updateValidationResult.isValid()) {
        issueService.update(currentUser, updateValidationResult)
    } else {
        log.warn updateValidationResult.errorCollection.errors
    }
0 votes
Laszlo Kremer
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 5, 2013

Meanwhile I found the .getOptionId() of the Option which returns the ID. The ValidationResult can be confusing as it says "Allowed values: 10100[option1], 10102[option2]" but you should only pass a String[] with the IDs.

SO the solution is:

1. get the selected values

List<Option> selectedvalues = (List<Option>) mutableIssue.getCustomFieldValue(cfProduct);

2. Iterate trough and get those IDs

List<String> selectedIDs = new ArrayList<String>();

if (selectedvalues != null)
{
	for (Option option : selectedvalues)
	{					
		selectedIDs.add(option.getOptionId().toString());			
	}
}

3.add the customfield value

createIssueInputParameters.addCustomFieldValue(cfProduct.getId(), selectedIDs.toArray(new String[selectedIDs.size()]));

That worked for me.

TAGS
AUG Leaders

Atlassian Community Events