Hi All-
I am trying create a script for updating multiple issue fields from a source field to a target field in one go. We have the following already determined for our field mappings:
I am aware of the the build in ScriptRunner Job that allows us to utilize a filter, but we have to do it field by field and we have over 20+ fields and thousands of issues.
Any help would be great!
Is this a one-time execution? Or are you looking to have this operation repeated at a high frequency? I'm asking because you mentioned "Scriptrunner Job" which are designed to execute a specific task based on a pre-set schedule.
Either way, it doesn't much matter, the best option i, is to use the methods made available by HAPI.
Just in the Scriptrunner Console, you can use JQL and HAPI to perform a pre-determined set of field update operations on all issues.
import com.atlassian.jira.event.type.EventDispatchOption
def jql = 'your jql to identify issues to update'
Issues.search(jql).each{issue->
issue.update{
setSendEmail(false) //adjust as needed
setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH) //adjust as needed
def multiFieldOptionList = issue.getCustomFieldValue('MultiCustomField1')
setCustomFieldValue('SingleSelect', multiFieldOptionList[0].value)
/* ... etc for all your other mappings */
}
}
HAPI will take care of all the underlying issue updates and identifying the correct option in the new field based on the text of the option value(s) of the old field.
Thanks Peter, so it doesn't seem to like the .value without passing it as string.
No signature of method: com.adaptavist.hapi.jira.fields.DumbFieldUpdater.set() is applicable for argument types: ([Ljava.lang.Object;) values: [[1.0]] Possible solutions: set([Ljava.lang.String;), get(), use([Ljava.lang.Object;), wait(), any(), grep()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you add and report back the output of
log.info "multiFieldOptionList result is $multiFieldOptionList (${multiFieldOptionList.getClass()})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script92.groovy: 16: Unexpected input: '"multiFieldOptionList result is $' @ line 16, column 10. log.info "multiFieldOptionList result is $multiFieldOptionList (${multiFieldOptionList.getClass()}) ^ 1 error </pre>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe share your full script... all I supplied were example syntax. You have to adjust for your use case and field names and field types etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies, I just took the HAPI portion that you provided and adjusted for my custom fields and jql. The test fields I was using are text from a single line to multi line.
import com.atlassian.jira.event.type.EventDispatchOption
def jql = 'issuekey=DT-13173'
Issues.search(jql).each{issue->
issue.update{
setSendEmail(false) //adjust as needed
setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH) //adjust as needed
def multiFieldOptionList = issue.getCustomFieldValue('CR #')
setCustomFieldValue('Technical Design Details', multiFieldOptionList[0].value)
/* ... etc for all your other mappings */
}
}
log.info "multiFieldOptionList result is $multiFieldOptionList (${multiFieldOptionList.getClass()})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try with the log like this:
import com.atlassian.jira.event.type.EventDispatchOption
def jql = 'issuekey=DT-13173'
Issues.search(jql).each{issue->
issue.update{
setSendEmail(false) //adjust as needed
setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH) //adjust as needed
def multiFieldOptionList = issue.getCustomFieldValue('CR #')
log.info "multiFieldOptionList result is $multiFieldOptionList (${multiFieldOptionList.getClass()}"
setCustomFieldValue('Technical Design Details', multiFieldOptionList[0].value)
/* ... etc for all your other mappings */
}
}
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.
Did you copy the full script in the last reply? I had fixed an issue with a missing double-quote.
Maybe you can include a screenshot that shows the full script and any errors.
Here is an expanded example that I was able to test in my environment (except I left out the setCustomValuePart):
import com.atlassian.jira.event.type.EventDispatchOption
def jql = '"Automatic Sub-Tasks" is not empty'
def nameOfMultiSelectField = 'Automatic Sub-Tasks'
def nameOfSingleSelectField = 'Technical Design Details'
Issues.search(jql).take(1).each{issue->
issue.update{
setSendEmail(false) //adjust as needed
setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH) //adjust as needed
def multiFieldOptionList = issue.getCustomFieldValue(nameOfMultiSelectField)
log.info "$issue.key: value of $nameOfMultiSelectField is $multiFieldOptionList (${multiFieldOptionList.getClass()})"
if(multiFieldOptionList instanceof List){
log.info "$issue.key: multiFieldOptionList.firstOption = ${multiFieldOptionList[0].value}"
} else {
log.error "$nameOfMultiSelectField is not returning a list of Options. This field doesn't work for this example."
}
//this will attempt to lookup an option in nameOfSingleSelectField that has the same string value as the first selected option in nameOfMultiSelectField. If there are no matching options, this will fail
//setCustomFieldValue(nameOfSingleSelectField, multiFieldOptionList[0].value)
/* ... etc for all your other mappings */
}
}
This is what it looks like when i execute:
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.