Jira version: v7.7.1
Scriptrunner version: 5.3.7
I found a script similar to the one below that I would like to implement using script runner.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get a pointer to the Implemented By user picker field and its value
def userCf = customFieldManager.getCustomFieldObjectByName("Developer")
def implUser = issue.getCustomFieldValue(userCf) as ApplicationUser
// If the Implemented By Field is not null then set the assignee
if(implUser){
issue.setAssigneeId(implUser.username.toString())
}
I have the script runner add-on, but when I put the above script in script-console, I get an error "the variable [issue] is undeclared". What am I missing?
Any help is greatly appreciated.
Thank you.
Hello,
Sorry for such a late reply on this!
I believe you just need to make your issue into a Mutable issue so that you have access to the setAssignee() method. You can do so by adding this line near the top of your code, below the import statements:
MutableIssue issue = issue as MutableIssue
You'll also need to add in the import for the Mutable Issue class, which can be done like so:
import com.atlassian.jira.issue.MutableIssue
Please let me know if this fixes the problem that you're seeing, or if you have any other questions.
Jenna
Thank you for your response Jenna.
I actually got my script to work. I was adding it to the wrong place apparently. It works when I add it in my jira workflow by creating a post function (Script Post-Function).
I was previously trying to add it under “add-ons”, “script runner”, “script console”.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great! I'm glad you got it working. :)
Just for future reference, the script console is where you would place script you want to be ran once on the entire instance. You were likely getting the '[issue] is undeclared' error because a specific issue isn't defined for the script console, you have to get the issue yourself if you want to run a script there using the IssueManager's getIssueByCurrentKey() method or something similar.
I would recommend that you read over the ScriptRunner documentation for more information on what you can do with the different types of scripts.
Jenna
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.
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.