How to access User object in Groovy script

Dipenkumar Patel March 20, 2015

HI There

I am currently working on Script Listener and try to create/access User Object based on name/Email address with JIRA 6.3.1 version. Below script I wrote but getUserObject() method got deprecated and not able to find alternate way to access it. First Bold line.

 

Other issue I have is how to get the Type of SubTask object when Iterating through SubTasks? Second Bold Line is it correct approach?

Can you please help me with these issues? Also How can I found that what is deprecated and what is not? Is there any way can get Java Class details. 

Script (Not tested yet):

if(ComponentAccessor.getProjectManager().getProjectObjByKey("IN").getKey().equalsIgnoreCase(issue.getKey())

&& !issue.getCustomFieldValue("Status").toString().equalsIgnoreCase("Deploy to Production")) {
log.debug("Assignee Email Address: " + issue.getAssigneeUser().getEmailAddress())
if (!(issue.getAssigneeUser().getEmailAddress().equalsIgnoreCase("RE Group Email Address")) || (!(issue.getAssigneeUser().getEmailAddress().equalsIgnoreCase("RM Group")))) {
def user = ComponentAccessor.getUserManager().getUserObject("RM Group")
issue.setAssignee(user)
ComponentAccessor.getComponent(IssueManager.class).updateIssue(ComponentAccessor.jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
log.debug("Issue \""+issue.getKey()+"-"+issue.getId()+"\" updated successfully.")
}
//Check for SubTask status and update parent accordingly.
 else if (subTaskManager.subTasksEnabled && !subTasks.empty) {
boolean isBlocked = false
boolean isDenied = false
boolean allApproved = false

for(MutableIssue subTask in subTasks){
log.debug("Issue Type: "+ subTask.getCustomFieldValue("Type").toString())
if(subTask.getCustomFieldValue("Type").toString().equalsIgnoreCase("Business Approval")) {
log.debug("Parent Status: " + subTask.getParentObject().getStatusObject().getName())
if (!subTask.getParentObject().getStatusObject().getName().equalsIgnoreCase("Approved")) {

}
}
}
}
}

 

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Tomasz Stec
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

1.To get user object (ApplicationUser preciselly) you can use this code:

ComponentAccessor.getUserUtil().getUserByName("John Smith")

or

ComponentAccessor.getUserUtil().getUserByKey("jsmith")

 

2.I assume you don't actually need IssueType object, but the name of the IssueType so to acomplish your goal:

 

 

for(MutableIssue subTask in subtasks){
	if("Business Approval".equalsIgnoreCase(subTask.getIssueTypeObject().getName())){
		// do something with "Bussiness Approval" subtask
	}
}

 

You can find JIRA JAVA API here:

 

cheers!

 

1 vote
Tomasz Stec
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2015

Yes and no, updateIssue() method will update all parts of issue: JIRA specific/custom fields and workflow status, BUT do not use this method to change issue's workflow status. To change workflow status you should perform full transition with validateTransition() and transition() methods. There is another important drawback. This method will perform only database queries. Index file of this issue won't be updated. So you need to reindex this issue to ensure consistency between database and indexes. Otherwise JIRA search will return malformed results.

0 votes
Dipenkumar Patel March 20, 2015

Thanks Tomasz for your quick reply. I will accept your answer once I test it.

 

One more quick question.

ComponentAccessor.getComponent(IssueManager.class).updateIssue(ComponentAccessor.jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

 

Above line of code will update  "System Field", "Custom Field", "Workflow" and User name everywhere? If not then how it can update all the places.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events