I am using the following code to assign user in a postfunction depending on a condition:
for(Issue subtask: issue.getSubTaskObjects()){
mutableIssue = issueManager.getIssueObject(subtask.getId())
if(mutableIssue.summary=='SomeSummary'){
ApplicationUser usera=userManager.getUserByName("SomePerson")
mutableIssue.setAssignee(usera);
issueManager.updateIssue(user, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false);
}
After creation, it is assigned to SomePerson. I also have a Kanban board which has a filter of displaying the issues which are only assigned to SomePerson. This issue doesn't show up there. When I go to the issue and manually assign it to some other user and then back to this user (SomePerson), this issue shows up on the kanban board. So I am assuming this is due to some error in assigning the issue programmatically. What is the problem here?
Hi Shagufta,
The following code will assign the issue TP-1 to the user with username admin
def issueKey = 'TP-1' def result = put('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .body([ fields:[ assignee: [name: 'admin'] ] ]) .asString() if (result.status == 204) { println 'Successfully assigned to admin' } else { println "Failed to assign to admin: ${result.status}: ${result.body}" }
Regards, Jon
Why would you want to do an REST call from an post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In JIRA Cloud, REST APIs are the only way to interact with JIRA. See the ScriptRunner documentation for more information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jon for clarification.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @Shagufta Gurmukhdas, try this code:
for(Issue subtask: issue.getSubTaskObjects()) { mutableIssue = issueManager.getIssueObject(subtask.getId()) if (mutableIssue.summary == 'SomeSummary') { ApplicationUser usera = userManager.getUserByName("SomePerson") mutableIssue.setAssignee(usera.directoryUser); issueManager.updateIssue(user, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But the setAssignee function is expecting an ApplicationUser object @Vasiliy Zverev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This code will not work in JIRA Cloud - see the ScriptRunner documentation for more info.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Class depends on JIRA version. Which one do you use?
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.
I did convert it using ApplicationUsers.from(usera.directoryUser) too, but the original issue is still there
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For me it is better to use this:
for(Issue subtask: issue.getSubTaskObjects()) { mutableIssue = issueManager.getIssueObject(subtask.getId()) if (mutableIssue.summary == 'SomeSummary') { ApplicationUser usera = userManager.getUserByName("SomePerson") mutableIssue.setAssigneeId(usera.getName()); issueManager.updateIssue(user, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It does not work. The above code just assigns that string with the name to the issue which is not clickable( a hyperlink of user's profile) . I mean, it does not assign it to the user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, let try this one:
for(Issue subtask: issue.getSubTaskObjects()) { mutableIssue = issueManager.getIssueObject(subtask.getId()) if (mutableIssue.summary == 'SomeSummary') { ApplicationUser usera = userManager.getUserByName("SomePerson") mutableIssue.setAssigneeId(usera.getKey()); issueManager.updateIssue(user, mutableIssue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works, but the original issue is still there(the kanban board of this user doesnt display the issue until manually assigned. )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this postfunction is used on create transiton?
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.
when this issue is transitioned to inprogress, the subtasks should be assigned to appropriate users automatically. And that is happening fine in the code. The only problem is, it isnt shpowing up on the users' kanban boards, but after i again manually assign it to them, it is showing. This is so strange..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, is there reindex postfunction after this script one?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes there is reindex after 2-3 steps. This script is the first step.
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.
I have never faced this case. I think that you should create another answer about 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.