Copy Cascading Select value to Single Select field

The Cascading Select field type in JIRA is incompatible with the new Zendesk Integration for JIRA. For this reason we are considering a change back to a single select field. This would affect 183K issues. I've read that the data is different from field to field, and it sounds like its not possible to copy the values via "Built-in Script" from ScriptRunner. Aside from standard bulk-update or workflow post-functions, is there some other way we can programmatically update sets of issues based on the cascading select value, without registering in the issue's change log? 

4 answers

1 accepted

Accepted Answer
1 vote

So, updating an issue without affecting the issue history is not well supported by the API.

That said, for a one-off mass-update, you could write a script for the Script Console that did the update. You'd want to get the results of a JQL query, then edit each item in the list.

This fairly naive example demonstrates how you'd take a cascading list custom field value and set a corresponding select list to the value that matched only the first list in the cascading select. You could modify it a bit to find more complex options, depending on what options you have configured for your single select list.

import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// edit this query to suit
def query = jqlQueryParser.parseQuery("project = JRA and assignee = currentUser()")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

log.debug("Total issues: ${results.total}")

def issueService = ComponentAccessor.getIssueService()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

results.getIssues().each {documentIssue ->
    // if you need a mutable issue you can do:
    def issue = issueManager.getIssueObject(documentIssue.id)
    def cascade = customFieldManager.getCustomFieldObjectByName("CascadingSelect") //your cascading select here
    def singleSelect = customFieldManager.getCustomFieldObjectByName("SelectListA") //your new select list here
    def singleSelectConfig = singleSelect.getRelevantConfig(issue)
    
    def optionsManager = ComponentAccessor.getOptionsManager()
    def options = optionsManager.getOptions(singleSelectConfig)
    def cascadeValue = cascade.getValue(issue)?.collect{it.value}?.getAt(0)?.toString()
    def optionToGet = options.find {it.value.toString() == cascadeValue}


    def inputParameters = issueService.newIssueInputParameters()
    inputParameters.addCustomFieldValue(singleSelect.idAsLong, optionToGet.optionId.toString())
    def updateValidationResult = issueService.validateUpdate(user, issue.id, inputParameters)
    issueService.update(user, updateValidationResult)
}

If you need to reuse this a lot for some reason, you could wrap it up in a Canned Script.

Hi Jonny,

I'm able to get the results of a query. When it comes to updating the field values, I get stuck on this line:

def cascadeValue = cascade.getValue(issue)?.collect{it.value}?.getAt(0)?.toString()

Error is referring to "it.value"... [Static type checking] -  no such property : value for class : java.lang.Object

I've reached out for help from my engineering organization, will follow up with them tomorrow to see if any resources are available.

What if I don't check the value of the fields, and just modify the query for each option individually? How would I say, "for these results, set singleSelect list value to X"?

Just to clarify, I don't want these issue to show as being "last updated" when I make this change, and don't want my name showing up anywhere either.

Thanks for the quick response, Jonny. This one-off solution won't work for 183K issues. sad 

I think my original example was unclear. I've updated it to more clearly show what I mean. It's only "one-off" in the sense that you'd run it once via the Script Console. It should update all 183k issues (though you might do a test batch first with a very selective JQL query, just to make sure it works as you expect).

Thanks Jonny. Will look into this and let you know how it goes.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,053 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you