Hello All,
The below script i am using for the giving the condition for Unassigned issue.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
if(issue.assigneeId=='Unassigned'){
issue.assigneeId = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
}
Is the above script correct ? Here if condition is not working.
Any Help/Suggestion would be appreciated.
Regards,
Dileep Kumar
When you want to update an issue you have to put the script in "post-function" . This code should work
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue;
if(issue.assigneeId){ // if assignee is empty
issue.assignee = ComponentAccessor.jiraAuthenticationContext.loggedInUser;
}
Thanks Tarun for the help !!
PFA. I have tested the above script, but its not able to update the Assignee with current/Logged in user.
Its taking the Unassigned value. Can you please help me regarding this ?
Regards,
Dileep Kumar
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.
Hi Tarun,
Thanks for the help !!
I am inserting my script in post function.
Any suggestion ?
Regards,
Dileep Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @DILEEP KUMAR
The code I showed is for updating the assignee but you also have to store the value in the DB, thus better use the issueService instead of issue.setAssignee method and then it should work for sure.
Please see 2 code samples here
https://community.atlassian.com/t5/Jira-questions/Updating-assignee-via-scriptrunner/qaq-p/637155
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.
Working code
import com.atlassian.jira.component.ComponentAccessor
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser;
def validateAssignResult = issueService.validateAssign(user,issue.id, user.username)
if(validateAssignResult.isValid()) {
issueService.assign(user,validateAssignResult)
}
If it works, then please upvote/accept the answer so that others are helped as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun,
Thanks for the help !!
I am able to get the issue assigned if its Unassigned/Automatic to logged-in user.
But, if am assigning issue to other users, its taking logged-in user.
So, Can you please put the condition on the above script ?
Like if Assignee==Unassigned/Automatic then only assignee==logged-in user.
Regards,
Dileep Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @DILEEP KUMAR
The APIs are available here - https://docs.atlassian.com/software/jira/docs/api/7.6.1/
As i have already shared a code sample which was the original question, thus it has been answered. Please go through the APIs docs and the Script Runner docs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun,
Thanks for the help !!
Yes you have answered.
But issue with your code is that even if i am assigning issue to other assignee its taking the logged-in user.
It should take the assignee as logged-in user, only if assignee is empty not if i am assigning it to other assignee.
Suppose, i have 10 different assignee then how i can make list and test the if condition ?
Regards,
Dileep Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can enter a condition to check if the assignee exists or not and if it didn't exist then you can assign the issue to current user whcih I have already shared with you, Hope this answers your question.
if(issue.assignee) {
//rest of the code here
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tarun,
Thanks for the help !! I will check and update the same.
Regards,
Dileep Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.