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
Hi @Mohamed Darmoul
This is the script you need, it can be run in the console:
import com.atlassian.jira.component.ComponentAccessordef 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
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?
The Scriptrunner Version 8.11 and I confirm the "Treatment Actor" isa single select user picker .
It looks like you're new here. Sign in or register to get started.