Hello friends,
I must perform a action in over 300 issues to fill a customfield. I has write a user define servlet as plugin, to do it.
In over 300 issues I look for some other fields and keywords in description and write a arraylist with the values of my checkboxes. Now my problem is to assign the it to customfield of issue.
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1") ArrayList<String> opt=new ArrayList<String>(); opt.add("Value1"); opt.add("Value3"); CustomField f = ComponentAccessor.getCustomFieldManager.getFieldByName("mycheckboxfield") issue.setCustomFieldValue(f,opt);
Why my last-line in code-Snipped doesn't assign the value to the issue?
(None exception or log-warnings was written.)
Know anyone a better way to reach this goal?
Thank you in advance for your spend time.
Best regards
Community moderators have prevented the ability to post new answers.
Hi,
I think you have to use an com.atlassian.jira.issue.customfields.option.Option object from the existing options of the multi-checkbox custom field fieldconfiguration as argument for setCustomFieldvalue().
If you want to use Strings as value you could use the IssueService.update() (https://developer.atlassian.com/display/JIRADEV/Performing+Issue+Operations).
For tasks like this I use the ScriptRunner Plugin, but maybe, the way Renjith suggested, using CLI, could be preferred.
Henning
If the sample is for CLI, you need to just read https://bobswift.atlassian.net/wiki/display/JCLI/Examples
jira --action updateIssue --issue "ZJIRACLI-4" --field "custom1" --values "xxxx"
Sorry ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IssueService issueService = ComponentAccessor.getIssueService(); IssueInputParameters issueInputParameters = new IssueInputParametersImpl(); issueInputParameters.addCustomFieldValue(cFO.getId(), "10017" ); UpdateValidationResult updateValidationResult = issueService.validateUpdate(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue.getId(), issueInputParameters);
issueService.update(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), updateValidationResult);
Is that correct so?
Whats the seperator for assign more than one optionfield-values?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try something like this within ScriptRunner:
import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.IssueInputParametersImpl Issue issue IssueService.UpdateValidationResult validationResult IssueService.IssueResult updateResult ComponentManager cm = ComponentManager.instance IssueService issueService = cm.issueService Long customFieldId = 10000 // Id of your customfield String[] myValues = ["15345","12345"] // String array of valid option Ids for your customfield User myUser = cm.jiraAuthenticationContext.getLoggedInUser() IssueInputParameters issueInputParameters // Find your issues here and use the following code on each of them issueInputParameters = new IssueInputParametersImpl([:]) issueInputParameters.addCustomFieldValue(customFieldId, myValues) validationResult = issueService.validateUpdate(myUser, issue.id, issueInputParameters) if (validationResult.isValid()) { updateResult = issueService.update(myUser, validationResult) if (!updateResult.isValid()) { updateResult.errorCollection.errors.each {log?.error "Error: $it"} } } else { validationResult.errorCollection.errors.each {log?.error "Error: $it"} }
Be aware that the value array will override the current selected checkboxes for the issue.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh... you already got it :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thats working fine, with some parameters...
But only I must switch off mail-sending durring this batch-opperation.
How can I switch off mails for only the affected issues and this shortly time?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To supress notifications you can surround the issueService code with
import com.atlassian.jira.util.ImportUtils boolean wasNotify = ImportUtils.isEnableNotifications() try { ImportUtils.setEnableNotifications(false) // update Issue .. } finally { ImportUtils.setEnableNotifications(wasNotify) // Reset notification state }
This disables notifications for the whole system, but maybe for this short time period this is ok for you.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or you could try adding
validationResult.getAdditionInputs().put("sendBulkNotification", false)
after the validation, but I didn't tried this by myself. Maybe you could report here if this works :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That method is only on TransitionValidationResult...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Why do you want to write a plugin? Just use JIRA CLI and get them updated using a script.
https://bobswift.atlassian.net/wiki/display/JCLI/JIRA+Command+Line+Interface
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I donn't have any practical experience with JIRA-CLI.
Can you write a example? I must check before some constulations in description-text and other field before I can fill my custom-value with the dynamic data's. Additional the script must be execute by an external application... So I need a call over HTTP/HTTPs (for example Servlet or Webservices).
I thik thats to comlex for JIRA-CLI... Or wath is you opinion?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
http://lmgtfy.com/?q=CLI+sample+for+update+issue+custom+field+JIRA
CLI is the easiest, for doing some thing for one time, no one usually writes a plugin.
If you want to really write some java code, then you can use the Script Runner Plugin and then use the script console.
https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner#ScriptRunner-ScriptRunnerpanel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I wirte java in ScriptRunnerPlugin, I has the same problem that I wrote in topic. Whats the different when I use Eclipse (with code-assistent, svn, ...) and write a plugin or I write java with plain-text-editor in ScriptRunnerPluin?
I need in both a solution to assign my value to the custom-checkbox-field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, that was just my preference, as I would just download CLI, check the examples in Bob's page, run a 'for' loop in my shell to update all the issues (probaly I will also 'getIssueList' using CLI first to get a list of issues).
Check out writing the plugin, it may be easier for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried to use the id of the option?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no success...
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1") ArrayList<Long> opt=new ArrayList<Long>(); opt.add(10017L); // ID from the CUSTOMFIELDOPTION-Table opt.add(10019L); CustomField f = ComponentAccessor.getCustomFieldManager.getFieldByName("mycheckboxfield") issue.setCustomFieldValue(f,opt);
doesn't work
and
OptionsManager opM = ComponentAccessor.getComponentOfType(OptionsManager.class); MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1") ArrayList<Option> opt=new ArrayList<Option>(); opt.add(opM.findByOptionId(10017L)); opt.add(opM.findByOptionId(10019L)); CustomField f = ComponentAccessor.getCustomFieldManager.getFieldByName("mycheckboxfield") issue.setCustomFieldValue(f,opt);
doesn't work
Has anyone more ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I has found flowing text in java-doc:
void com.atlassian.jira.issue.MutableIssue.setCustomFieldValue(CustomField customField, Object value)
Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading.
<dl><dt>Parameters:</dt><dd>customField the CustomField</dd><dd>value the value.</dd></dl>
To actually set a custom field value, useCustomField.updateIssue(com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem, MutableIssue, java.util.Map)
The value is correctly assign the issue-object (last code-snippet), when I hover in eclipse-debug, but it was not store in database!
How I get the content for variable com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem ??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.