Error in creating a sub-task for jira 6

I am getting the following error while creating a sub-ask on the create transition of a issue. Script was working fine in jira 5. After upgrading to jira 6 I get the following errors for users.

No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject()

Pls help

this is the code to link the subtask

-----------------------------------------------------------------------------------------------------

//Linking the issue with parent

Map<String,Object> newIssueParams = ["issue":newSubtask] as Map<String,Object>;

log.warn("\n\n\nnewIssueParams: ---> ${newIssueParams.dump()}\n\n\n"); //Debug the parameters

//Get the user who is currently logged in

def currentUser = jiraAuthenticationContext.getUser();

log.warn("\n\n\n******\n\n\n");

//creating the issue that links the subtask and the current User

newSubtaskGV = issueManager.createIssueObject(currentUser,newIssueParams);

log.warn("***");

//reindexing

indexManager.reIndex(newSubtaskGV);

log.warn("***");

//link the subtask with the parent issue

subTaskManager.createSubTaskIssueLink(EmpIssue, newSubtask, componentManager.getJiraAuthenticationContext().getUser());

log.warn("Subtask ${newSubtask.getKey()} is created from ${issue.getKey()}");

log.warn("You're fine till here");

log.warn("\n\n");

issueLinkManager.createIssueLink(issue.getId(),newSubtask.getId(),Long.parseLong(linkID),0,user)

ComponentManager.getInstance().getIndexManager().reIndex(newSubtask)

---------------------------------------------------------------------------------------------------

Script stops because of this line

//creating the issue that links the subtask and the current User

newSubtaskGV = issueManager.createIssueObject(currentUser,newIssueParams);

log.warn("***");

9 answers

use this to get user object

User user=ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();

Thank you for the help.

What import statement has to be used for this? I am not getting the method getDirectoryUser() in IDE. It says cannot resolve symbol getDirectoryUser()

you have to use following dependencies in pom.xml

&lt;dependency&gt;
&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
&lt;artifactId&gt;jira-core&lt;/artifactId&gt;
&lt;version&gt;${jira.version}&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.atlassian.jira&lt;/groupId&gt;
&lt;artifactId&gt;jira-api&lt;/artifactId&gt;
&lt;version&gt;${jira.version}&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

I'm not sure what your code's issue is, but jiraAuthenticationContext.getUser(); is deprecated. You should probably change it to jiraAuthenticationContext.getLoggedInUser();.

I am facing another problem in jira 6.

def public CreateSubtask(MutableIssue issue, String mySummary, User newassign )

{

CustomField cfemp = customFieldManager.getCustomFieldObjectByName( "Employee" );
User cfempv = issue.getCustomFieldValue(cfemp);
log.warn("Employee issue assignee :" +cfempv);

}

CreateSubtask(issue, "Profile Creation - Resume",cfempv);

This gives the following error

java.lang.ClassCastException: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to com.atlassian.crowd.embedded.api.User

Any solution how do I pass the User parameter in CreateSubtask?

you declare User using
import com.atlassian.crowd.embedded.api.User;

I am getting this error for Users

The script failed : javax.script.ScriptException: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'admin(admin)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User'

I'm getting this error for Users

The script failed : javax.script.ScriptException: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'admin(admin)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User'

you just try using User as a String object rather than User object

I tied using it as a string. It says

No signature of method: com.onresolve.jira.groovy.postfunction.Script5.CreateSubtask() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.lang.String, com.atlassian.jira.user.BridgedDirectoryUser) values: [SCS-1355, Assign owner for BDM -, admin:1]

Possible solutions: CreateSubtask(com.atlassian.jira.issue.MutableIssue, java.lang.String, java.lang.String)

I don't know groovy syntax, but I just modified your code as below:

//Linking the issue with parent

Map&lt;String,Object&gt; newIssueParams = ["issue":newSubtask] as Map&lt;String,Object&gt;;

log.warn("\n\n\nnewIssueParams: ---&gt; ${newIssueParams.dump()}\n\n\n"); //Debug the parameters

//Get the user who is currently logged in

def currentUser = jiraAuthenticationContext.getUser();

log.warn("\n\n\n******\n\n\n");

//creating the issue that links the subtask and the current User

newSubtaskGV = issueManager.createIssueObject(currentUser.getName(),newIssueParams);

log.warn("***");

//reindexing

indexManager.reIndex(newSubtaskGV);

log.warn("***");

//link the subtask with the parent issue

subTaskManager.createSubTaskIssueLink(EmpIssue, newSubtask, ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser());

log.warn("Subtask ${newSubtask.getKey()} is created from ${issue.getKey()}");

log.warn("You're fine till here");

log.warn("\n\n");

issueLinkManager.createIssueLink(issue.getId(),newSubtask.getId(),Long.parseLong(linkID),0,user)// also you check which user you are giving it should be ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser()


ComponentManager.getInstance().getIndexManager().reIndex(newSubtask)

---------------------------------------------------------------------------------------------------

Script stops because of this line

//creating the issue that links the subtask and the current User

newSubtaskGV = issueManager.createIssueObject(currentUser,newIssueParams);

log.warn("***");

I got the answer to this

def public CreateSubtask(MutableIssue issue, String mySummary, User newassign)

{

CustomField cfemp = customFieldManager.getCustomFieldObjectByName( "Employee");
DelegatingApplicationUser cfempv = issue.getCustomFieldValue(cfemp);
User empuser = cfempv.getDirectoryUser();

}

CreateSubtask(issue, "Profile Creation - Resume",empuser);

This works in jira 6 without any errors of typecasting.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

176 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you