Hi,
I have Scriptrunner and Automation for Jira plugins.
I'm trying to have a scriptrunner action in Automation for Jira that updates a custom field with values from two other fields.
Namely, I'm trying to concatenate the Issue Key and the Issue Summary in the custom field.
Are you able to provide help?
try the following one
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParameters
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy")
def userManager = ComponentAccessor.getUserManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("YourCustomFieldID")
def issueManager = ComponentAccessor.getIssueManager()
def user = userManager.getUserByName("YourAdmin")
def customFieldValue = issue.key +" "+ issue.summary
issue.setCustomFieldValue(customField,customFieldValue)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Update the following line
ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customFieldId=10711")
With
ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10711)
this code is working with the latest script runner version, please if you still have the problem mention your instance version
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have Version 5.5.0.
I changed the ("customFieldId=10711") to just (10711) but I'm still getting the same "cannot find matching method" error on the last two lines of the script.
I also tried swapping the last two lines of code to Antoine's suggestion but that gives me the following error:
unable to resolve class ModifiedValue
@ line 17, column 38.
unable to resolve class DefaultlssueChangeHolder
@ line 17, column 96.
Code is currently as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParameters
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy")
def userManager = ComponentAccessor.getUserManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10711)
def issueManager = ComponentAccessor.getIssueManager()
def user = userManager.getUserByName("EPP Team")
def customFieldValue = issue.key +" "+ issue.summary
def customFieldOldValue = issue.getCustomFieldValue(customField)
customField.updateValue(null, issue, new ModifiedValue(customFieldOldValue, customFieldValue), new DefaultIssueChangeHolder())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add these two imports :
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this but running into an error. Here is what I get:
[Static type checking] - Cannot find matching method
com.atlassian.jira.issue.Issue#setCustomFieldValue(com.atlassian.jira.iss
java.lang.String). Please check if the declared type is correct and if
the method exists.
@ line 16, column 1.
The code I'm running is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParameters
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy")
def userManager = ComponentAccessor.getUserManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customFieldId=10711")
def issueManager = ComponentAccessor.getIssueManager()
def user = userManager.getUserByName("EPP Team")
def customFieldValue = issue.key +" "+ issue.summary
issue.setCustomFieldValue(customField,customFieldValue)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I would advise to swap the two last lines for these :
def customFieldOldValue = issue.getCustomFieldValue(customField)
customField.updateValue(null, issue, new ModifiedValue(customFieldOldValue, customFieldValue), new DefaultIssueChangeHolder())
Antoine
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.