We recently upgraded to JIRA 7.9.2 and Scriptrunner 5.4.12 and some of the scripts which were being used in one of our workflows have stopped working. The person who wrote them originally has left the company and I'm not a groovy expert, so I'm hoping someone can help point me in the right direction.
Script106.groovy:50
[Static type checking] - Inconvertible types: cannot cast com.onresolve.scriptrunner.runner.stc.MissingCustomFieldTransportInfo to java.lang.String
@ line 50, column 41.
This is the line that seems to be erroring:
int assignTo = Integer.parseInt((String)args.get("field.subIssueRoleId"));
This is part of a script that is triggered as a post function and generates separate sub-tasks for each role in the parent workflow. I believe this line is supposed to grab the roleID of the role to assign the task to.
Here's the whole script:
import org.apache.log4j.Category;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.config.ConstantsManager;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.exception.CreateException;
import com.atlassian.jira.issue.index.IndexException;
import com.atlassian.jira.user.UserUtils;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.util.ImportUtils;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.util.BuildUtils;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.crowd.model.user.User;
public class CreateSubtaskForRoleActions{
private final SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
private final IssueManager issueManager = ComponentAccessor.getIssueManager();
private final IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
private final ProjectManager projectManager = ComponentAccessor.getProjectManager();
private final ConstantsManager constantsManager = ComponentAccessor.getConstantsManager();
private final JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
private final ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager);
private final IssueIndexingService indexManager = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class);
private final GroupManager groupManager = ComponentAccessor.getGroupManager();
private final UserManager userManager = ComponentAccessor.getUserManager();
private final CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
private static final Category log = Category.getInstance("com.onresolve.jira.groovy.GroovyFunctionPlugin");
public void createSubTask(Map transientVars, Map args){
Issue parentIssue = (Issue) transientVars.get("issue");
int assignTo = Integer.parseInt((String)args.get("field.subIssueRoleId"));
ProjectRole role = projectRoleManager.getProjectRole(new Long(assignTo));
def usersgroup = userManager.getGroup("jira-users")
groupManager.getUserNamesInGroup("jira-users").each {
def user = userManager.getUserByName(it);
if (projectRoleManager.isUserInProjectRole(user, role, parentIssue.getProjectObject())) {
MutableIssue issueObject = issueFactory.getIssue();
issueObject.setProjectObject(projectManager.getProjectObj(parentIssue.getProjectObject().getId()));
issueObject.setIssueTypeObject(constantsManager.getIssueType((String) args.get("field.subIssueTypeId")));
issueObject.setSummary((String)args.get("field.subIssueOverview"));
issueObject.setDescription((String) args.get("field.subIssueDescription"));
issueObject.setComponent(parentIssue.getComponents());
issueObject.setReporter(parentIssue.getAssignee());
issueObject.setAssignee(user);
int priority = Integer.parseInt((String) args.get("field.subIssuePriorityId"));
if (priority == 0) {
issueObject.setPriorityObject(parentIssue.getPriority());
}
else {
issueObject.setPriorityObject(constantsManager.getPriorityObject((String) args.get("field.subIssuePriorityId")));
}
Map params = new HashMap();
params.put("issue", issueObject);
try {
Issue subTask = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), params);
subTaskManager.createSubTaskIssueLink(parentIssue, subTask, authenticationContext.getLoggedInUser());
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
/if ((BuildUtils.getCurrentBuildNumber() as Long) < 614) {
ManagerFactory.getCacheManager().flush(com.atlassian.jira.issue.cache.CacheManager.ISSUE_CACHE, issue)
}/
indexManager.reIndex(subTask);
// Now, flip it back off
ImportUtils.setIndexIssues(wasIndexing);
} catch (CreateException e) {
log.error("Could not create sub-task", e);
} catch (IndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/*private void preventDuplicateSubtasks(Issue parentIssue, Map args){
Collection subTasks = parentIssue.getSubTaskObjects();
for(Iterator i = subTasks.iterator(); i.hasNext();){
MutableIssue mutableIssue = (MutableIssue)i.next();
log.debug("Child object key: " + mutableIssue.getKey() + " summary: " + mutableIssue.getSummary() + " " + mutableIssue.getStatusObject().getName());
/*if(((String)args.get("field.subIssueOverview")).equals(mutableIssue.getSummary())){
String status = mutableIssue.getStatusObject().getName();
if(status.equals("Open") || "Passed".equals(status) || status.equals("Not Required")){
return
}
}
}
}*/
}
(new CreateSubtaskForRoleActions()).createSubTask(transientVars, args)
Can you try to change line 34
private final ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(projectManager);
with
private final ProjectRoleManager projectRoleManager = ComponentAccessor.getProjectManager()
and try again?
By the way, I think you'r trying to create new subtasks with this script, but you can do it with a much simpler code, even with built-in postfunctions. There is any reason to do it this way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually I found out I didn't have an issue after all. There were a bunch of other errors which I had fixed, but this one error I couldn't get to go away. Per Adaptavist support, you don't need to actually worry about static type checking errors! So it was something else in the script that I had fixed already which was causing the script to fail, and when I ran it even with the static type error, it works now.
As to the complexity of this, as I said, this was written by someone who has left the company and I'm not an expert in Groovy, I'm just trying to keep it running! I'm sure there's an easier way to do what they did.
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.