I'm trying to write a postfunction script to check the value of a custom field (Assigned Tester). If it's empty, I want to get the reporter of the issue, check if he is part of the Assigned Tester role, and if so, assign him to this custom field.
I'm getting stuck on this error java.lang.ClassCastException: com.atlassian.jira.user.BridgedDirectoryUser cannot be cast to com.atlassian.jira.user.ApplicationUser
I'm new at this, and I can't figure out how to debug... I tried system.out.println, but I don't know where I would see it? I trailed the output log atlassian-jira.log (that's where I see the error message), but I don't see anything that I'm trying to print out.
Here is the part of my code that is having trouble, I appreciate any tips.
ComponentManager componentManager = ComponentManager.getInstance() CustomField assignedTester = componentManager.getCustomFieldManager().getCustomFieldObjectByName("Assigned Tester") if (assignedTester.getValue(myIssue) == null){ //check if the reporter can be a tester User myReporter = myIssue.getReporter() //User myOldTester = issue.getCustomFieldValue(assignedTester) ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager ProjectRole testRole = projectRoleManager.getProjectRole("Assigned Testers") if (projectRoleManager.isUserInProjectRole(myReporter, testRole, issue.getProjectObject())){ //the reporter can be a tester, so assign him IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); assignedTester.updateValue(null, issue, new ModifiedValue(null, myReporter), changeHolder) } }
Community moderators have prevented the ability to post new answers.
To get debug messages you can use the object log (org.apache.log4j.Category). It's already binded to your script. So if you write
log.error "Debug message"
you will see this message in the atlassian-jira.log. You could implement different levels of debug messages. log.debug(), log.info(), log.warn() and log.error() and set the log level at the beginning of your script.
log.setLevel(org.apache.log4j.Level.DEBUG)
In this way you can develop with log level debug and after finishing raise the level to error to get only important messages in the log.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Take a look at this page: https://developer.atlassian.com/display/JIRADEV/Renamable+Users+in+JIRA+6.0#RenamableUsersinJIRA6.0-ConvertingbetweentheUserobjectandtheApplicationUserobject
You will need to convert the user types, or get a new User object from the key of the applicationUser (or something).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
jamie, thanks for the link. still working on this, and after many hours, not getting anywhere.
which user needs to be converted? the reporter needs to be converted to application user to update the custom field value? and how would i do that... thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the latest version of ScriptRunner, if you're creating a simple script rather than a listener class, it appears you need to initialize the log object yourself:
def log = Logger.getLogger("com.example.script") log.setLevel(Level.DEBUG) log.info("...")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to look at the server log files where JIRA is running, System.out.print will appear there. I found my logs in catalina.out for example, apache
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a reason why you use myIssue and issue in your source?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this jira 6? Possibly there is a bug in isUserInProjectRole in jira 6.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.