Hi,
how to traverse through a Select List (multiple choices) values and count number of values updated in it using groovy script.
i have one requirement where I need to check the number of values updated as part of custom field i,e "Impacted sub-systems" of Select List (multiple choices). Please advice, how to do it?
I tried to use the below code/script based on the answers shared in our Atlassian community.
But unable to traverse for 2nd vlaue, etc using these methods - please suggest what is the right method to achieve the same.
1st Approach tried: -------------------- //'Impacted sub-systems' is a multiple choice single select list custom field def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems") def selectedComponents = issue.getCustomFieldValue(componentCF) selectedComponents?.each { LazyLoadedOption it -> } 2nd approach tried: ------------------- def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems") Group group = issue.getCustomFieldValue(componentCF) as Group if (group){group?.each { def issueFactory = ComponentAccessor.getIssueFactory() def issueManager = ComponentAccessor.getIssueManager() def newIssue = issueFactory.cloneIssue(issue) }
Now using the 1st approach, I can traverse through the number of custom field values and able to create number of clones equivalent to number of custom field values updated in a JIRA issue now.
There was an issue with setCustomFieldValue of different data types and it's resolved now.
But I would like to create "Issue Links from parent JIRA issue(i,e from which I cloned) to Cloned issues in the below same loop.
Please advice how to create Issue links in both the directions means "is cloned by(Inward)" link to be established in the parent JIRA issue and "clones(Outward)" link to be established from all the cloned JIRA issues to a parent JIRA issue.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.customfields.option.LazyLoadedOption Issue issue = issue def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() //'Impacted sub-systems' is a multiple select list custom field def componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted sub-systems") def selectedComponents = issue.getCustomFieldValue(componentCF) //'Subsystem' is a select list (single choice) def subSystemCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Subsystem") selectedComponents?.each { LazyLoadedOption it -> def issueFactory = ComponentAccessor.getIssueFactory() def issueManager = ComponentAccessor.getIssueManager() def newIssue = issueFactory.cloneIssue(issue) // because the sub-system is a select list (single choice) we should find the option with that value (if any) def optionToSet = ComponentAccessor.getOptionsManager().getOptions(subSystemCF.getRelevantConfig(issue)).find {option -> option.value == it.value} newIssue.setCustomFieldValue(subSystemCF, optionToSet) Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object> issueManager.createIssueObject(currentUser, newIssueParams) }
You've said "through the updated multiple custom field values" again, without explaining it, and that's the main problem with your question. Your "clone issues and inherit data" is now clear (which wasn't explained before), but you really need to explain the "updated". Updated in what?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would like to traverse through the updated multiple custom field values one by one, need to create those many clone issues and copy the custom field values one by one into another custom field of cloned issues respectively.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does it mean that on transition value of this custom field is changed and you need to find added/deleted options?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code doesn't really bear a lot of relationship to your question, apart from using iterators.
Could you explain your actual requirement though? "how to traverse through a Select List (multiple choices) values and count number of values updated in it using groovy script." is not clear on the goal. I can see you want to do something in a script, and that you want to work with values from a select list. But not what you want to do. "Number of values updated in what?"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.