Hi,
We are using jira 5.1 with Script Runner 2.0.6,
When i tried to upgrade to 2.1.15 ( to enable "issueFunction" in JQL ) i got the follwoing error in a script which we are using :
----------------
2014-02-06 11:45:10,638 TP-Processor3 ERROR odedpr 705x313x1 3xla21 172.17.13.173 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
groovy.lang.MissingMethodException: No signature of method: com.onresolve.jira.groovy.canned.workflow.postfunctions.CreateICSubtasks.getUser() is applicable for argument types: (java.util.HashMap) values: [[args:[class.name:com.onresolve.jira.groovy.GroovyFunctionPlugin, ...], ...]]
Possible solutions: getLog(), getUserUtil(), getName(), getAt(java.lang.String)
package com.onresolve.jira.groovy.canned.workflow.postfunctions
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.issuetype.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.util.SimpleErrorCollection
import com.onresolve.jira.groovy.canned.CannedScript
import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
import com.atlassian.jira.ComponentManager
import org.ofbiz.core.entity.GenericValue
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
class CreateICSubtasks extends AbstractCloneIssue implements CannedScript {
public final static String FIELD_ROLE_NAME = "Assigned Role"
public final static String FIELD_UPDATE_TYPE = "Update Type"
private def toOpen = [
"New Installer": [["Technical task", "Developer", "IC Developer"], ["Project Setup", "Project Setup", "Project Setup"], ["Offer Flow", "Offer Manager", "Flow Manager"]],
"New DLM": [["Technical task", "Developer", "IC Developer"], ["Project Setup", "Project Setup", "Project Setup"], ["Offer Flow", "Offer Manager", "Flow Manager"]],
"New Offer": [["Technical task", "Developer", "IC Developer"]],
"Update": [["Technical task", "Developer", "IC Developer"]]
]
protected Boolean isUpdate(Issue issue) {
CustomField cf = componentManager.getCustomFieldManager().getCustomFieldObjectByName(FIELD_UPDATE_TYPE)
return (issue?.getCustomFieldValue(cf) != null)
}
String getName() {
return "Auto-creates sub-tasks for installcore projects."
}
String getDescription() {
return "Create subtasks used for InstallCore projects. Only supports New projects."
}
List getCategories() {
["Function"]
}
List getParameters(Map params) {
[]
}
public ErrorCollection doValidate(Map params, boolean forPreview) {
SimpleErrorCollection errorCollection = new SimpleErrorCollection()
return errorCollection
}
protected IssueType getIssueTypeByName(String name) {
IssueType rv = null
componentManager.getConstantsManager().getAllIssueTypeObjects().each() {
type ->
if (type.name == name) {
rv = type
}
}
return rv
}
void AddIssue(MutableIssue oldIssue, IssueType issueType, User assignee, ProjectRole role, User reporter, User currentUserObj) {
if (issueType == null) {
return
}
IssueManager issueMgr = componentManager.getIssueManager()
def wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true
IssueFactory issueFactory = ComponentManager.getInstance().getIssueFactory()
MutableIssue newIssue = issueFactory.getIssue()
newIssue.projectObject = oldIssue.projectObject
newIssue.issueTypeObject = issueType
newIssue.priorityObject = oldIssue.priorityObject
newIssue.summary = "AUTO-CREATED: " + issueType.name + " - " + oldIssue.summary
if (assignee) {
newIssue.assignee = assignee
}
newIssue.reporter = reporter
def cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(FIELD_ROLE_NAME)
newIssue.setCustomFieldValue(cf, role.name)
Issue newIssueGv = issueMgr.createIssueObject(currentUserObj, newIssue)
indexManager.reIndex(newIssueGv);
ImportUtils.indexIssues = wasIndexing
SubTaskManager subTaskManager = componentManager.getSubTaskManager()
subTaskManager.createSubTaskIssueLink(oldIssue, newIssueGv, currentUserObj)
}
Map doScript(Map params) {
Issue issue = params['issue'] as MutableIssue
if (! issue.subTasks.size() == 0) {
log.warn ("This issue ($issue) already had sub-tasks... doing nothing.")
return params
}
if (issue.getIssueTypeObject().isSubTask()) {
log.warn ("This issue ($issue) is already a sub-task... doing nothing.")
return params
}
User currentUserObj = getUser(params)
def cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName("Account Manager")
User reporter = issue.getCustomFieldValue(cf) ?: currentUserObj
ProjectRoleManager projectRoleManager = (ProjectRoleManager) componentManager.getComponentInstanceOfType(ProjectRoleManager.class);
String type = issue.issueTypeObject.name
type = isUpdate(issue) ? "Update" : type
log.warn("IsUpdate " + isUpdate(issue) + " :--> $type")
toOpen[type].each() {
task ->
String issueTypeName = task[0]
String assigneeField = task[1]
String roleName = task[2]
log.debug("Want to open a $issueTypeName for $assigneeField")
cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(assigneeField)
log.debug("Assignee CF is " + cf.inspect())
User assignee = issue.getCustomFieldValue(cf)
ProjectRole role = projectRoleManager.getProjectRole(roleName)
IssueType issueType = getIssueTypeByName(issueTypeName)
log.debug("Really going to open a " + issueType?.name + " for user " + assignee?.name + " and role " + role?.name)
AddIssue(issue, issueType, assignee, role, reporter, currentUserObj)
}
return params
}
String getDescription(Map params, boolean forPreview) {
return "Will create InstallCore subtasks"
}
public Boolean isFinalParamsPage(Map params) {
true
}
}
What kind of script is this? Do you define a class and is the method getUser() available in this class?
Yes - I added more of the script.
class CreateICSubtasks extends AbstractCloneIssue implements CannedScript {
Map doScript(Map params) {
Issue issue = params['issue'] as MutableIssue
if (! issue.subTasks.size() == 0) {
log.warn ("This issue ($issue) already had sub-tasks... doing nothing.")
return params
}
if (issue.getIssueTypeObject().isSubTask()) {
log.warn ("This issue ($issue) is already a sub-task... doing nothing.")
return params
}
User currentUserObj = getUser(params)
def cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName("Account Manager")
User reporter = issue.getCustomFieldValue(cf) ?: currentUserObj
ProjectRoleManager projectRoleManager = (ProjectRoleManager) componentManager.getComponentInstanceOfType(ProjectRoleManager.class);
String type = issue.issueTypeObject.name
type = isUpdate(issue) ? "Update" : type
log.warn("IsUpdate " + isUpdate(issue) + " :--> $type")
toOpen[type].each() {
task ->
String issueTypeName = task[0]
String assigneeField = task[1]
String roleName = task[2]
log.debug("Want to open a $issueTypeName for $assigneeField")
cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(assigneeField)
log.debug("Assignee CF is " + cf.inspect())
User assignee = issue.getCustomFieldValue(cf)
ProjectRole role = projectRoleManager.getProjectRole(roleName)
IssueType issueType = getIssueTypeByName(issueTypeName)
log.debug("Really going to open a " + issueType?.name + " for user " + assignee?.name + " and role " + role?.name)
AddIssue(issue, issueType, assignee, role, reporter, currentUserObj)
}
return params
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, looks like you should try
User currentUserObj = WorkflowUtils.getUser(params)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks alot Henning ! I'll check check it ( as soon as I'll get my Jira login problem solve :) )
I'm newbie with Java and Groovy .. so please understand any silly questions :)
I suspected that the method was changed .. so looked here - https://docs.atlassian.com/jira/5.1.8/overview-summary.htmlfor the javadoc for my jira version, but all I could find was a bunch of getUser() methods.
For next time .. how can tell if a a class/method was changed?
p.s do I need to import any additional class?
Your help is much appreciated !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem :-)
WorkflowUtils is a class from the Script Runner package (import com.onresolve.jira.groovy.canned.utils.WorkflowUtils is needed). The method combines several sources where the script can get the current user, depending on the current situation.
In Java/Groovy a method belongs to a class/object. If you call it without a class or object in front of it, the compiler assumes the method belongs to the current object. And in your object there is no getUser() method, so you get the error.
For API changes you can take a look here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again!
Now I'm getting the following error : ( I updated all the script in the question )
groovy.lang.MissingPropertyException: No such property: indexManager for class: com.onresolve.jira.groovy.canned.workflow.postfunctions.CreateICSubtasks
Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you have to get the indexManager. :-)
import com.atlassian.jira.issue.index.IssueIndexManager
IssueIndexManager indexManager = ComponentAccessor.getIssueIndexManager()
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.