Hi
I am trying to update the CustomField using Script Runner , CustomField is Radio button Type with Default Value is No & other options are E1,E2 & E3 , while trying to execute i am getting the error ,
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def targetField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Email"}
def changeHolder = new DefaultIssueChangeHolder();
targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), "E2"), changeHolder);
Error is ( same Script i was able to update with Text Field )
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:68) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.updateValue(AbstractSingleFieldType.java:146) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:462) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:432) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source) at Script737.run(Script737.groovy:8)
Email_Radio_Button.png
I used the following additional code in an escalation service, with no action, and it worked fine:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.index.IssueIndexingService import com.atlassian.jira.issue.util.DefaultIssueChangeHolder def customFieldManager = ComponentAccessor.getCustomFieldManager() def indexManager = ComponentAccessor.getComponent(IssueIndexingService) def targetField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "RadioButtons"} def cfConfig = targetField.getRelevantConfig(issue) def option = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Maybe' } def changeHolder = new DefaultIssueChangeHolder(); targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), option), changeHolder); indexManager.reIndex(issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes was missing issuemanager.updateissue() or field.updatevalue() in my answer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is what it says - you are trying to set a value in a radio button field which expects an option, not a string. The "E2" in your "set value" code needs to be a select-list option rather than a simple string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic,
i tried it using select-list option but was not successful , is any sample groovy script to help in select-list option to update a custom Field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How are you building the option from the string that names it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May be you can try to use the API function instead of the groovy clause
import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); CustomField cf = customFieldManager.getCustomFieldObject("customfield_10000"); def cfConfig = cf.getRelevantConfig(issue) issue.setCustomFieldValue(cf, ComponentAccessor.optionsManager.getOptions(cfConfig).getOptionForValue('Field Value', null);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
Tried it , but it is not updating the field , no errors while executing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As Nic indicates, you need to handle the selection as an "object" instead of a string in text. My coworker Cody recently wrote a script that did this, I think I can strip it down for you here.
import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); CustomField cf = customFieldManager.getCustomFieldObject("customfield_10000"); def cfConfig = cf.getRelevantConfig(issue) issue.setCustomFieldValue(cf, ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Field Value' });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thanks for script , but this update the Raido button cutsomFeild Field to Null value instead of E1
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObject("customfield_11210");
def cfConfig = cf.getRelevantConfig(issue)
issue.setCustomFieldValue(cf, ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'E1' })
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That would suggest that E1 is not a valid option for the field. I suspect it's because your it.toString will not work for two reasons:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I make sure i have String correct by selecting the database , i tired updating Single Text Field & Radio button , but not getting reflected .
Is there any other CustomField type which i should use in Groovy Script .
Based on update using scriptrunner only my JQL works .
After the update from Script runner the values are assgined as null value for the CustomField
mysql> select * from customfieldoption where CUSTOMFIELD=11405;
+-------+-------------+-------------------+----------------+----------+-------------+------------+----------+
| ID | CUSTOMFIELD | CUSTOMFIELDCONFIG | PARENTOPTIONID | SEQUENCE | customvalue | optiontype | disabled |
+-------+-------------+-------------------+----------------+----------+-------------+------------+----------+
| 11006 | 11405 | 11906 | NULL | 0 | E1 | NULL | N |
| 11007 | 11405 | 11906 | NULL | 1 | E2 | NULL | N |
| 11008 | 11405 | 11906 | NULL | 2 | E3 | NULL | N |
| 11009 | 11405 | 11906 | NULL | 3 | E0 | NULL | N |
+-------+-------------+-------------------+----------------+----------+-------------+------------+----------+
4 rows in set (0.00 sec)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
An option object is not just a string, you need to get the option out so you can set it. The table you've looked at here is one option per line, and you can see that it's not just "E2" on there. E2 is just the name, the option object is the name, an id, a couple things about where the option applies, a type and a flag for disabling it. The code you've used before will get an option, if your "if" statment was comparing correctly. But you're comparing an option with a string. So it's always false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vijar... your script looks OK to me... can you put the option in a variable called option and then log.warn (option), and see what you have in your logs.
You could use:
find { it.value == 'E1' })
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {it.value == 'E2' }
log.warn (value)
Added but still same result , here is the log output
2016-03-29 20:14:51,265 http-nio-8080-exec-13 WARN vijay.sridhar 1214x85038x1 qdzee8 10.10.99.161 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [c.o.s.c.jira.utils.ConditionUtils] E2
2016-03-29 20:14:51,797 http-nio-8080-exec-13 WARN vijay.sridhar 1214x85038x1 qdzee8 10.10.99.161 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.EscalationService/preview [c.o.s.c.jira.utils.ConditionUtils] E2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So the option is there.
In your original post you used targetField.updateValue, but later you mentioned issue.setCustomFieldValue.
If you are not doing a transition, you need to use the former method (or IssueService.updateIssue).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
Initially i tried with targetField.updateValue & then issue.setCustomFieldValue with , both are executing without error but still it is not updating . this is the final script which i am using
is there any specific Custom filed type i need to use ? like Label , Radio Button, Single Text etc for updating using script runner ?
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObject("customfield_11210");
def cfConfig = cf.getRelevantConfig(issue)
log.debug "Need Feedback From: '"+cf+"' cleared to"
issue.setCustomFieldValue(cf, ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.value == 'E2' });
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {it.value == 'E2' }
log.warn (value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what JIRA version and plugin version?
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 know that's a fair point, my script source was written for Single Select fields. Perhaps it doesn't work with Radio Buttons. As I have time I can take a look...
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.