Hello Everyone, We are using Jira 7.6.4 and Scriptrunner 5.4.11, The task is to autopopulate a Selectlist customfield in Jira on the target issue. I have tried variuos scripts from the blog but none of them are working for me. Is something changed on Scriptrunner plugin recently? Can someone help me to get the correct script including the correct packages.
I have tried the below scripts:
CustomField customField = customFieldManager.getCustomFieldObject("customfield_17100");
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(customField.getRelevantConfig(issue), null));
Option newOption = options.getOptionById("Campaign"); // Check your option id
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption );
customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());
===============*=======================
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, value)
Hello @Vineet Kumar
try this
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, value)
Thanks for the response Mark, I have already tried the above option, I am getting the below error.
Caused by: java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39) [jira-api-7.6.4.jar:?]
at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:81) [classes/:?]
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606) [osworkflow-2.9.0-atlassian-1.jar:2.9.0-atlassian-1]
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:742) [classes/:?]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try enclosing the value within a collection.
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, [value])
I did something similar and it worked for me.
This is what I have:
Issue newIssueObject = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase(newIssueID.toString().trim())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField targetProjectBoardField = customFieldManager.getCustomFieldObject("customfield_10144")
String targetProjectBoardFieldValue = newIssueObject.getCustomFieldValue(targetProjectBoardField)
log.info "Current Project Board Value for target issue ("+newIssueID.toString().trim()+") is:" +targetProjectBoardFieldValue
if(targetProjectBoardFieldValue!=null && !targetProjectBoardFieldValue.equals("") && targetProjectBoardFieldValue.length()>1){
log.info "Updating Target Issue Project Board"
OptionsManager optManager = ComponentAccessor.getOptionsManager();
Options options = optManager.getOptions(targetProjectBoardField.getRelevantConfig(newIssueObject));
log.info "Available Options: " + options
Option newOption = options.getOptionById(Long.parseLong(affectedBoardsFieldValue));
log.info "Identified Option: " + newOption
def fieldConfig = targetProjectBoardField.getRelevantConfig(newIssueObject)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.optionId.toString().trim() == affectedBoardsFieldValue.toString().trim() }
log.info "Final Value:" + value
def changeHolder = new DefaultIssueChangeHolder()
def issueCustomFieldValues = newIssueObject.getCustomFieldValue(targetProjectBoardField)
log.info "issueCustomFieldValues: "+issueCustomFieldValues
ModifiedValue mVal = new ModifiedValue(issueCustomFieldValues, [value])
log.info "mVal: "+mVal
targetProjectBoardField.updateValue(null, newIssueObject, mVal, changeHolder)
log.info "Target Issue Project Board has been updated."
log.info "Validation - " + newIssueObject.getCustomFieldValue(targetProjectBoardField)
}
Modify per your needs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much @Gundlupet Sreenidhi .
The below script works fine.
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Solution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.value == 'Campaign'
}
issue.setCustomFieldValue(cfSelect, [value])
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.