Hi everybody,
After looking for a solution myslef, I'm kind out of idea right now. Here's the situation :
Environment : Jira 5.2.11 / Script Runner 2.1.15
When creating an issue, (in post-function) I want to :
- Extract values from a cascading select field (Nature of the Request - cf id:17000)
- Check if the word 'QlikView' is in the first value
- Update another cascading field (System and Sub-System - cf id 11201) with values (existing in the field configuration, let's say Data - QlikView)
So far, I have this script I modified to fit my needs, BUT the updating process doesn't manage to update the cf 11201 value.
When checking the script with the script console, I don't have any error message and it gives me back the correct value (Data - QlikView).
But when I put the script in the workflow, the value isn't updated in the cf 11201
// and if I look at the logs, i have the following message :
// Caused by: java.lang.NoClassDefFoundError: com/opensymphony/user/User
// --> caused by a plugin old version
Do you have any clues about what's wrong?
Thanks!
import org.apache.log4j.Category
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.view.CustomFieldParamsImpl
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutStorageException
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext;
MutableIssue issue = issue
CustomFieldManager cfManager2 = ComponentManager.getInstance().getCustomFieldManager()
// name of the first cascading field I will extract the value in order to check it
CustomField cf2 = cfManager2.getCustomFieldObject(17000)
String first = issue.getCustomFieldValue(cf2)?.values()*.value[0]
String second = issue.getCustomFieldValue(cf2)?.values()*.value[1]
// name of the cascading field where I want to put my new value
CustomField categoryCF = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName("Système et sous-système");
CustomFieldParams cfVal = issue.getCustomFieldValue(categoryCF) as CustomFieldParams
if (categoryCF == null || !(categoryCF.getCustomFieldType() instanceof CascadingSelectCFType)) {
log.error("Expected customfield doesn't exist or doesn't have the expected type.");
}
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
Option parentOptionObj = optionsManager.findByOptionId(11124); // value to put in first list
Option childOptionObj = optionsManager.findByOptionId(11211); // value to put in second list
Map<String,Object> newValues = new HashMap<String, String>();
// checking if the value in the first cascading field is correct
if (first.contains('QlikView')) {
newValues.put(null, parentOptionObj);
newValues.put("1", childOptionObj);
// then updating the second cascading field with new values
categoryCF.updateValue(null, issue, new ModifiedValue(cfVal,newValues), new DefaultIssueChangeHolder());
issue.store()
}