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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot