Scriptrunner - unable to resolve class Edited

Hello,

I want to change the assignee of an issue based on a checkbox. if the value "Related" is check in the custom filed "Customer Related", I want the assignee to be change to some one else.

I tried to do the following using scriptrunner post function:

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.user.util.UserManager;

ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField customer_Related= customFieldManager.getCustomFieldObject("customfield_xxxx");
customer_Related_Value = issue.getCustomFieldValue(customer_Related);
if (customer_Related_Value*.value.contains("Related"))
{
    User usera = userManager.getUser('Username');
    issue.setAssignee(usera);
    issue.store()
}

But I got the following error:

 

The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script63.groovy: 12: unable to resolve class User 
 @ line 12, column 10.
       User usera = userManager.getUser('Username');
            ^

1 error

Thanks,

Ben

2 answers

1 accepted

0 vote

You need to import a class to represent the user.  I suspect

import com.atlassian.jira.user.ApplicationUser

is the one you want.  I'm assuming JIRA 7 here.

Also, getUser is deprecated, so I'd use getUserByName instead.

import com.atlassian.jira.user.ApplicationUser , didnt solved it.

how do you suggest to change the code to fit with getUserByName?

 

You need to use the class that provides too, ApplicationUser, not User.  getUserByName can replace getUser directly

import com.atlassian.jira.user.ApplicationUser , didnt solved it.

how do you suggest to change the code to fit with getUserByName?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

232 views 1 18
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