Hello there,
will try to be quick.
Building automation routine in scriptrunner jobs.
All the stuff is running fine, but the final set values back into checkboxes CF is failing without any errors to error log, but doing nothing.
part of routine:
def productsCf = customFieldManager.getCustomFieldObject("customfield_24970")
def productsCfValue = issue.getCustomFieldValue(productsCf)
def productsCfValueId = productsCfValue =~ pattern
productsCfValueId = productsCfValueId.findAll() //stored IDs of all product(s) in portfolio
def commonValues = productTeamPlusImpactedProduct.intersect(productsCfValueId)
def missingValuesInPortfolio = productTeamPlusImpactedProduct.minus(commonValues)
def missingValuesInEpics = productsCfValueId.minus(commonValues)
def missingValueNamesInPortfolio = []
def productsCfConfig = productsCf.getRelevantConfig(issue)
def productsCfOptions = ComponentAccessor.optionsManager.getOptions(productsCfConfig)
for (product in productTeamPlusImpactedProduct)
{
product = product.toString()
for (productsCfOption in productsCfOptions)
{
productsCfOption = productsCfOption.toString()
if (productsCfOption.contains(product)) {missingValueNamesInPortfolio.add(productsCfOption)}
}
}
def optionsToSet = productsCfOptions.findAll { it.value in missingValueNamesInPortfolio }
issue.setCustomFieldValue(productsCf, optionsToSet)
log.fatal productsCfOptions
log.fatal optionsToSet
log.fatal productsCfOptions.first().class
log.fatal optionsToSet.first().class
log.fatal issue
log.fatal issue.class
Results from logs:
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: [<385>,<356>,<347>,<355>,<351>,<343>,<354>,<386>,<350>,<344>,<348>,<359>,<349>,<353>,<360>,<355>,<352>]
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: [<356>,<351>,<350>,<359>,<349>,<353>,<360>,<352>]
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: class com.atlassian.jira.issue.customfields.option.LazyLoadedOption
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: class com.atlassian.jira.issue.customfields.option.LazyLoadedOption
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: CJPORT-286
2022-11-18 14:14:37,744 FATAL [runner.ScriptBindingsManager]: class com.atlassian.jira.issue.IssueImpl
So obviously, I trying to setCustomFieldValue on CJPORT-286 which is IssueImpl as expected with set of LazyLoadedOption as expected.
But nothing is set. Not entry in any log at all.
Maybe I am missing something, but this kind of code always works at other customers.
Any ideas?
Thanks, Tom
BTW: Routine is not finished, so please do not point to missing null pointers or other proof stuff.
Hi @Tomáš Vrabec ,
setCustomFieldValue sets a custom field value on the Issue Object, but does not write it to database.
So, I believe, you need to add the store method.
Ahoj @Hana Kučerová
You just made my day!
Totally forgot, that this is not a post function.
Replaced
issue.setCustomFieldValue(productsCf, optionsToSet)
productsCf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(productsCf), optionsToSet), changeHolder)
And it works like charm.
Díky! :-)
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.
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.