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?
Community moderators have prevented the ability to post new answers.
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.
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 }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.