Hi,
I have written a script to assigna value to a custom field of select field type. I want to change the value of the field to 'Yes' option. I added a add comment statement to the code which would show the value of the field after I set it to 'yes'. The output comment is [Yes].
But when I search for issues with 'Yes' option for the custom field as the filter, the issue doesnt show up.
Can some one tell me what might be the issue?
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.index.IssueIndexManager import com.opensymphony.workflow.WorkflowContext import org.apache.log4j.Category import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.user.ApplicationUsers ComponentAccessor componentAccessor= ComponentAccessor.newInstance() CustomFieldManager customFieldManager = componentAccessor.getCustomFieldManager() IssueManager issueManager = componentAccessor.getIssueManager() String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller(); def tgtField = customFieldManager.getCustomFieldObjectByName("Test-GlobDefect") def tgtFieldValue = issue.getCustomFieldValue(tgtField) OptionsManager optionsManager = ComponentAccessor.getOptionsManager() Option option = optionsManager.getOptions(tgtField.getRelevantConfig(issue)).getOptionForValue("No", null); issue.setCustomFieldValue(tgtField ,[option]) issueManager.updateIssue(componentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false) CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Test-GlobDefect"} cfwt = issue.getCustomFieldValue(srcField).toString() commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class) commmgr.create(issue, currentUser,cfwt , true) issue.store()
you add the statement
ComponentAccessor.getIssueIndexManager().reIndex(issue);
at the end and check.
Hi,
I realized there is some issue with this line:
issueManager.updateIssue(componentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I think componentAccessor.getJiraAuthenticationContext().getLoggedInUser() would be there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you tried by adding reindex code ?
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.
where you are adding this code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check setFieldValue method here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We've had a problem with multi-select fields (from what I gather that's the type of your field), where we couldn't filter the information by their values. The way I fixed it is, I made the multi-select field behave like the default Component field in Jira (i.e. add lables for each option). I did that by adding this JavaScript to the description of the multi-select field:
<script type="text/javascript"> (function($) { // "customfield_10400" is the number of the custom // multiselect field you want to change as e.g. // seen at the end of the "configure" page url of // the field you want to change this way AJS.$("#customfield_10400 option[value='-1']").remove(); //Removes the default value "None" function convertMulti(id){ if (AJS.$('#'+id+"-textarea").length == 0){ new AJS.MultiSelect({ element: $("#"+id), itemAttrDisplayed: "label", errorMessage: AJS.params.multiselectComponentsError }); } } AJS.toInit(function(){ convertMulti("customfield_10400"); }) JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { AJS.$("#customfield_10400 option[value='-1']").remove(); convertMulti("customfield_10400"); }); })(AJS.$); </script>
After that everything worked like a charm.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.