Hello Community ,
Can you please help me on creating a script with scriptrunner to set a user pricker field that retrieve the last user who set a status"Traité" in an issue .
Thank you in advance for your help
This is the script you need, it can be run in the console:
import com.atlassian.jira.component.ComponentAccessor
def curIssue = Issues.getByKey('WEB-2')
def changeItems = ComponentAccessor.getChangeHistoryManager().getChangeHistories(curIssue).reverse()
def changeItem = changeItems.find{ changeItem -> changeItem.getChangeItemBeans().find{ changeItemBean -> changeItemBean.field == "status" && changeItemBean.toString == "Done"}}
def author = changeItem.getAuthorObject()
curIssue.update{
setCustomFieldValue('Custom User Picker Field', author)
}
Just to run through the script, first we get the issue we want to update (this will change if you want to bulk perform this action, or have this script elsewhere).
Next we get the change history of the issue, and reverse that list, as it defaults to earliest first. We want to search from the latest.
Next we need to find the Change Item we want, so for each Change Item, get get all Change Item Beans. We then search these to see if there is one that changes the status, and that changes the status to the correct status name. Once we get one that matches that criteria, we know we have the correct Change Item.
Once we have the correct Change Item, we get the Author, and then use HAPI to update the custom field with that user.
Could you give this a try and let me know how you get on?
Kind regards,
Bobby
Thank you @Bobby Bailey , I have changed the status name , the ticket and the field name and I got this error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you let me know what version of ScriptRunner you are using please?
And also, just to confirm, 'Treatment Actor' is a single select user picker field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Scriptrunner Version 8.11 and I confirm the "Treatment Actor" isa single select user picker .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This looks like the error checking system in the editor might not be totally in sync with the editor. Could you try just running a simple script that returns “hello world” then paste back in the script and see if the same error is still there?
Kind regards,
Bobby
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.