I'm trying to right a groovy script to conditionally set a customfield, but I'm getting an error. I can't seem to find an example that matches my need. Can anybody help?
Here's my attempt:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue MutableIssue myIssue = issue ComponentManager componentManager = ComponentManager.getInstance() CustomField customField = componentManager.getCustomFieldManager().getCustomFieldObjectByName('Integration Checked') IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); customField.updateValue (null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(customField), 'Needed'), changeHolder)
The error I am getting is:
java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option at com.atlassian.jira.issue.customfields.impl.SelectCFType.getDbValueFromObject(SelectCFType.java:69) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:161) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:831) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:505) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:487) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source) at Script6.run(Script6.groovy:16)
It sounds like I'm dealing with the custom field as if it was simple text, and not a select list. But, how do I fix it?
Thanks!
See Hennings answer (and give him a vote):
Please tell me what is wrong with this script? It is returning NULL.
Requirement: Need to update the value of a custom field from NULL to the value specified in the script.
----------------------------------------------------------------------------------------------------------
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
def fieldid = 14601L //field id; currently having null value
def dbValue = "8.0.8" //New value to be assigned to the custom field
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TIK-3039"); //issue in JIRA
MutableIssue myIssue = issue;
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldid); //Identification of Custom Field Object
myIssue.setCustomFieldValue(customField,dbValue); //updating the value from "Null" to the value declared above "dbValue"
----------------------------------------------------------------------------------------------------------
Best regards,
Nishant
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.