You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi Everyone,
I have tried customizing many of the scripts that I have seen in these community responses, but I just cannot find one that works exactly and all of my attempts at making it work on my own have failed. Please help if you can. I really appreciate your time!
Lesley
I am currently using this script to try and update the assignee of a newly created issue to the value of a custom field (user picker, single select). I am copying the custom field from its linked issue, but it may be that the issue isn't getting fully created before it tries to run this script and doesn't know the value of the custom field yet.
If you have a better idea, here is my use case: an issue is auto-created as a linked issue (that's working), and I want to set the assignee of this new issue to the value of a custom field, which was filled-in on the original issue.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_15741")
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser
UserManager userManager = ComponentAccessor.getUserManager();
issue.setAssignee((user))
Hi @Lesley_Groh,
can you try below code for assigning ticket after fetching value from custom field
def issueService = ComponentAccessor.getIssueService()
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)
Also if you are using this script in post-function, verify the order you placed
BR,
Leo
Thank you, Leo! I updated it to this. I will give it a go. Yes, I am using a post-function on the "Create" Issue step. The order in which I am using this script is the last step of the create issue (after "Fire a Issue Created event. . .").
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
def issueService = ComponentAccessor.getIssueService()
def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_15741")
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)
UserManager userManager = ComponentAccessor.getUserManager();
issue.setAssignee((user))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I don't think last 2 lines are required as IssueService,assign will assign the ticket
and if it's not working. try placing this function on top/before Re-index an issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it failed with this error, but did create the ticket and assigned to the project admin (me).
groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script95
at Script95.run(Script95.groovy:8)
I will try the re-order and removing those last two lines. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suppose you'll have to modify the custom field line like below
def cField = customFieldManager.getCustomFieldObjectById("customfield_15741")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm sorry for the delay - I had some meetings.
I was performing your suggestions one at a time and trying them.
"I don't think last 2 lines are required as IssueService,assign will assign the ticket" -
I tried removing the two lines that you suggested, and then, the issue was not assigned to the project admin, instead, the re-assignment to my custom field value failed and the issue remained assigned to the reporter of the linked issue.
Then, I was going to try this: "and if it's not working. try placing this function on top/before Re-index an issue," but there isn't a Re-index issue step in my create issue. So, I didn't do that one.
Then, I tried this: "I suppose you'll have to modify the custom field line like below," but I receive two different errors at the script writing level, before I can update the changes:
The first error is:
"Cannot find matching method com.atlassian.jira.issue.CustomFieldManager#getCustomFieldObjectByID(java.lang.S
Please check if the declared type is correct and if the method exists."
The second error is:
""Cannot find matching method com.atlassian.jira.issue.MutableIssue#getCustomFieldValue(java.lang.Object).
Please check if the declared type is correct and if the method exists."
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lesley_Groh,
I didn't get time to look into it. finally I got it worked like below
1. Script I used
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Field Name")
def assignee = issue.getCustomFieldValue(cfUpdate) as ApplicationUser issue.setAssignee(assignee)
2. I placed this post-function on top, even before create issue originally
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leo, Unfortunately, I am seeing this error message when I copy the script into the Post Function. I tried to change it to what it wants, but then, I receive an error below. Thanks for your continued efforts! Lesley
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 @Lesley_Groh,
You can ignore the first warning. try to proceed with warning don't update line 3 with suggestions
mostly it should work even if there is a warning. it is working script in my system
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
YAY!!! If I could do a back flip, I would! THANK YOU!!! It is working. I appreciate your quick responses and help with getting this to work!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This worked for me too for a very similar scenario, thanks Leo! (and Lesley for making the post in the first place) :)
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.