Hello
I am writing a plugin for a Jira 4.4.3 system, and am having a great deal of difficulty figuring out how to update the value in a custom field of type SelectList.
It appears that something has changed in 4.4, since the examples I've used from previous versions do not work.
The release notes for 4.4 http://confluence.atlassian.com/display/JIRA/Plugin+Developer+Notes+for+JIRA+4.4#PluginDeveloperNotesforJIRA44-Single-andMulti-SelectCustomFieldChanges refer to changes in the way Select CF types are implemented. However, I can't find any relevant code that demonstrates updating these fields.
Here's what I have so far:
CustomField teamProjectList = customFieldManager.getCustomFieldObjectByName("TeamProjectList"); Object selectValue = issue.getCustomFieldValue(teamProjectList); System.out.println("TeamProjectList: " + selectValue); FieldLayoutItem fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(teamProjectList); OptionsManager optionsManager = (OptionsManager)ComponentManager.getComponentInstanceOfType(OptionsManager.class); CustomFieldParams newSelectValue = new CustomFieldParamsImpl(); Option newOption = optionsManager.findByOptionId(new Long(10101L)); Collection<String> newCollection = new ArrayList<String>(); newCollection.add(newOption.toString()); System.out.println("New Option is: " + newOption.toString()); newSelectValue.put(null, newCollection); teamProjectList.updateValue(fieldLayoutItem, issue, new ModifiedValue(selectValue, newSelectValue), new DefaultIssueChangeHolder());
The two print statements show the correct values. However, the modiefied value never makes it into the issue (although later updates in the same plugin are there). This issue seems peculiar to SelectList types.
The following answer confirms that I need to use an Option object, but an example of it's use would be much appreciated.
https://answers.atlassian.com/questions/10431/how-do-i-update-the-value-of-a-selectcftype-field
cheers
Community moderators have prevented the ability to post new answers.
You don't need to create a newSelectValue which is CustomFieldParams.
Just pass newOption into the ModifiedValue as shown and see if it works:
teamProjectList.updateValue(fieldLayoutItem, issue, new ModifiedValue(selectValue, newOption), new DefaultIssueChangeHolder());
Thanks for your feedback, Jobin.
I tried your suggestion, but the field is still not updated. In fact, the previous value is removed. Kind of useful through, since it indicates that some sort of change is made.
Here is the new code:
System.out.println("--->>>"); teamProjectList.updateValue(fieldLayoutItem, issue, new ModifiedValue(selectValue, "Fork-Food"), new DefaultIssueChangeHolder()); System.out.println("--->>>");
Here is the output from the server window:
[INFO] [talledLocalContainer] --->>> [INFO] [talledLocalContainer] 2012-01-18 13:25:41,297 http-2990-4 WARN admin 805x2367x1 10jivgn 127.0.0.1 /secure/CreateIssueDetails.jspa [issue.customfields.impl.SelectCFType] of type class java.lang.String [INFO] [talledLocalContainer] 2012-01-18 13:25:41,299 http-2990-4 WARN admin 805x2367x1 10jivgn 127.0.0.1 /secure/CreateIssueDetails.jspa [issue.customfields.impl.SelectCFType] of type class java.lang.String [INFO] [talledLocalContainer] --->>>
It really looks as though the String update item is not being accepted.
Any ideas?
cheers
Wayne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oops - my bad! I tried the wrong code. Your solution works.
Thank you very much, Jobin!
cheers
Wayne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried above code to jira 4.4.3 version but it is working.is there any thing to modify.
MutableIssue mIssue = (MutableIssue) transientVars.get("issue"); CustomField customField = customFieldManager.getCustomFieldObjectByName("Agen"); Object selectValue = mIssue.getCustomFieldValue(customField); Project project = mIssue.getProjectObject(); IssueContextImpl issueContext = new IssueContextImpl(project.getId(), null); FieldConfig fieldConfig = customField.getRelevantConfig(issueContext); Long lp = Long.valueOf(100); System.out.println("slecteVlaue::::"+selectValue); OptionsManager optionsManager = (OptionsManager)ComponentManager.getComponentInstanceOfType(OptionsManager.class); Option option = optionsManager.findByOptionId(Long.valueOf(11502)); System.out.println("Option selected:::"+option.toString()); FieldLayoutItem fieldLayoutItem = null; try{ fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(mIssue).getFieldLayoutItem(customField); } catch (FieldLayoutStorageException e) { // TODO: handle exception } customField.updateValue(fieldLayoutItem, mIssue, new ModifiedValue(selectValue, option), new DefaultIssueChangeHolder()); System.out.println("Start:4");
Thanks!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is not working for jira 4.4.3.what might be the reason?
MutableIssue mIssue = (MutableIssue) transientVars.get("issue"); CustomField customField = customFieldManager.getCustomFieldObjectByName("Agen"); Object selectValue = mIssue.getCustomFieldValue(customField); System.out.println("slecteVlaue::::"+selectValue); FieldLayoutItem fieldLayoutItem = null; try{ fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(mIssue).getFieldLayoutItem(customField); } catch (FieldLayoutStorageException e) { // TODO: handle exception } OptionsManager optionsManager = (OptionsManager)ComponentManager.getComponentInstanceOfType(OptionsManager.class); Option newOption = optionsManager.findByOptionId(Long.valueOf(11501)); System.out.println("Option selected:::"+newOption.toString()); customField.updateValue(fieldLayoutItem,mIssue,new ModifiedValue(selectValue,newOption),new DefaultIssueChangeHolder()); System.out.println("Start:4<--->");
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.