I'm trying to update a custom field on a series of issues. I'm obviously missing something because the examples I'm culling from here on Answers give me the following error:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.DocumentIssueImpl.setCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl, java.lang.Integer) values: [CreatedInHelpdesk, 1] Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)
Here's my code as of now:
import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.CustomFieldManager jqlQuery = 'project != HELPDESK' fromProject = 'HELPDESK' result = '' def customFieldManager = componentManager.getCustomFieldManager() def changeHistoryManager = ComponentAccessor.getChangeHistoryManager() getFilterResult (jqlQuery,log).each{ Issue issue -> oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id) oldKeys.findAll{it==~/$fromProject.*/}.each{ result += "$it -> ${issue.key}\n" } CustomField helpdeskField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CreatedInHelpdesk'} issue.setCustomFieldValue(helpdeskField, 1) } return result List<Issue> getFilterResult(String jqlSearch, log) { def searchService = ComponentAccessor.getComponent(SearchService.class); def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() List<Issue> issues = null def parseResult = searchService.parseQuery(user, jqlSearch); if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) issues = searchResult.issues } else { log.error("Invalid JQL: " + jqlSearch); } return issues }
You need to get a MutableIssue, by using issueManager.getIssueObject(issue.id)
Then you can set the field value. But you should probably use IssueService to do a proper update.
Here is some code to update a field without creating a new change item and all that:
def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Name of custom field"} def changeHolder = new DefaultIssueChangeHolder(); tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "some new value"),changeHolder);
What type of field is it?
issue.setCustomFieldValue(helpdeskField,
1
)
may not be right.
Thanks, exactly the pointer I needed.
Needed this, as well:
import com.atlassian.jira.issue.ModifiedValue
The code snippet that worked for me:
(Observant folks will note that since the setting snippet isn't inside the 'findAll', it's updating _every_ issue in the result. Oops. But at least it worked!)
getFilterResult (jqlQuery,log).each{ Issue issue -> oldKeys = changeHistoryManager.getPreviousIssueKeys(issue.id) oldKeys.findAll{it==~/$fromProject.*/}.each{ result += "$it -> ${issue.key}\n" } CustomField helpdeskField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'CreatedInHelpdesk'} helpdeskField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(helpdeskField), 1 as Double),changeHolder); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jamie Echlin [Adaptavist] , I have a similar requirement. In the code snippet given by you, is it possible to pass a list of values and have one of them select manually? My requirement is to make a field(component, versions etc) editable before the issue gets cloned. This means, I donot want the parent values to be copied on the clone issues and it should give me an option to select the values myself before issue gets clone. Please let me know if this can be done.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How can you adapt this to a user type custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jamie
I am using the clones and links script. I want the condition to copy over 3 custom fields, but I can't figure out how to change the script to do that.
I tried to add 3 custom fields names in the {'cf1,cf2,cf3'} but it didn't work, and I can't repeat the code on line 3.
This is the code that I am using.
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Name of CF'}
issue.setCustomFieldValue(cf, sourceIssue.getCustomFieldValue(cf))
Any help would be greatly appreciated.
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.