I have a problem with this script as inline post function.
According to after trying to set the assignee the first way nothing changes. The second way changes the assignee according to the log, but in reality .
Can anybody help with this issue?
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.user.util.UserManager import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.bc.issue.IssueService import org.apache.log4j.Level import org.apache.log4j.Category Category log = Category.getInstance("com.onresolve.jira.groovy.ISDCreateIssuePostfunction") UserManager userManager = ComponentAccessor.getUserManager() IssueService issueService = ComponentAccessor.getIssueService() log.setLevel(Level.DEBUG) log.debug "Starting Postfunction..." // getting current user ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser() log.debug "Current user is: " + currentUser // getting the issue issueKey = issue.getKey() MutableIssue mutableIssue = issueService.getIssue(currentUser, issueKey).getIssue() log.debug "Current issue key is: " + mutableIssue.getKey() log.debug "Current issue assignee is: " + mutableIssue.getAssignee() userToAssign = userManager.getUserByName("t.shahverdyan") log.debug "Setting user to \"" + userToAssign + "\"." // validating user assign IssueService.AssignValidationResult assignValidationResult = issueService.validateAssign(currentUser, mutableIssue.getId(), userToAssign.getKey()); log.debug "Validate result is: " + assignValidationResult.isValid() + "" // assigning user. 1st way IssueService.IssueResult issueResult = issueService.assign(currentUser, assignValidationResult) log.debug "Assign result is: " + issueResult.isValid() + "" // checking log.debug "Current issue assignee is: " + mutableIssue.getAssignee() // assigning user. 2nd way mutableIssue.setAssigneeId(userToAssign.getKey()) // checking log.debug "Current issue assignee is: " + mutableIssue.getAssignee()
log:
screenshot after transition with script postfunction: image2015-8-28 14:39:46.png
UPDATE
Here is real script - . Depending on custom field (Service Type) value the assignee can be different. Also there can be no assignee. But before assigning I want to check if the person has the permission to be assigned to the issue. For that I use IssueService.validateAssign() then IssueService.assign().
UPDATE 2
Here is post functions order - .
Log from script - .
Result - .
Community moderators have prevented the ability to post new answers.
@Jamie Echlin [Adaptavist] could you please help with this issue? I don't know how else to get a support on this issue.
did my answer works?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try something easier:
P.S. put this code before those 2 default postfunction:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.user.util.UserManager import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor userManager = (UserManager) ComponentAccessor.getUserManager() MutableIssue issue = issue User NewAssignee = userManager.getUser('t.shahverdyan') issue.setAssignee(NewAssignee)
https://answers.atlassian.com/questions/176759
BR.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guilherme, hi! Sorry for late answer. I just tried and it works. Thanks. But with my version I was trying to solve 2 issues: 1. assign using current JIRA API. UserManager.getUser() method is deprecated - https://docs.atlassian.com/jira/latest/com/atlassian/jira/user/util/UserManager.html#getUser(java.lang.String) 2. do all operation by checking if current user the permission to do it The problem is that I don't understand why during script session I get that the assignee is set, but in reality it is not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also why issueService.assign() does not work, though issueResult.isValid() returns true.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist] , could you please help with this issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey, to get current user use: import com.atlassian.jira.user.ApplicationUser; ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser(); More info: https://developer.atlassian.com/static/javadoc/jira/reference/com/atlassian/jira/user/ApplicationUser.html Remember, you can use: User NewAssignee = userManager.getUser('t.shahverdyan')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or this: User user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hope it help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I forgot two things: "2. do all operation by checking if current user the permission to do it" - You can control it by workflow validator, it's easier . "Also why issueService.assign() does not work, though issueResult.isValid() returns true. " I have no idea at all
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please accept my answer if it worked :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guilherme, I know how to get the current user. It is in my code above. About the operation checking. The validator will not work as my real script has switch operator in it and in some cases it doesn't assign at all. I already answered you about getUser() method. I'll edit my original question. Thanks anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What's your real script? Slim it down to the simplest possible case and post it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And that doesn't work? What position does it have in the list of post-functions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist] I posted the answers. Could you please look into it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make it last in the list and it will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you put your error log here?
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.