Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to implement the field past Assignee

Dmitry May 29, 2023

Hi All,

i want to make a gobal field "Past Assignee" for subsequent automations at the WF level.

I'm thinking of using Custom Script Field from Scriptrunner or better Listeners for Events: Issue Assigned.

I tried to use the case How do i get first assignee of issue using scriptrunner, but it did not work out.

If you still tell me the code, I will be very grateful.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 29, 2023

Hi @Dmitry

Could you please provide more information, i.e. when do you want the Custom Field to be updated?

Is it when the issue is being created or updated or when it transitions?

The change history is the correct approach, as shown in the community discussion that you have shared.

Could you please share the code you are testing along with your configurations so I can look and provide some suggestions?

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Dmitry May 29, 2023

I would like to dynamically capture the past Assignee in the field "Past Assignee".

More:

  • The issue has been created. (Past Assignee = EMPTY)
  • The issue has been assigned to user1. (Past Assignee = EMPTY).
  • The issue has been assigned to user2. (Past Assignee = user1)

I expect a vision as in the example Last Comment Scripted Field, but if they pulled out the past comment.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 29, 2023

Hi @Dmitry

Thank you for getting back and providing your feedback.

In your last comment, you mentioned:-

I expect a vision as in the example Last Comment Scripted Field, but if they pulled out the past comment.

This documentation is not applicable as it is for the ScriptRunner for Jira Cloud and not Server / DC.

For your requirement, the best approach would be to use the Listener with the Issue Updated event.

Below is a sample working code for your reference:-

import com.adaptavist.hapi.jira.issues.Issues
import com.adaptavist.hapi.jira.users.Users
import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def userSearchService = ComponentAccessor.userSearchService
def issue = Issues.getByKey(event.issue.key)

def changeHistory = changeHistoryManager.getChangeHistories(issue)
def userNames = [] as List<String>

changeHistory.each {
if (it.changeItemBeans['field'].toString() == '[assignee]') {
userNames << it.changeItemBeans['toString'].first()
}
}

def users = userSearchService.findUserKeysByFullName(userNames.first()) as List<String>

issue.update {
setCustomFieldValue('Sample User Picker 1', Users.getByKey(users.first()))
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Listener configuration:-

config.png

With this Listener, the User Picker field will always be set to the First Assignee, no matter how many times the Assignee is to change.

Please note that this sample code uses ScriptRunner's HAPI feature. To be able to use this feature, please ensure that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.3.0.

Below are a couple of test screens for your reference:-

1. When the issue is first created, no Assignee has been added; hence the User picker field is not updated as expected, as shown in the screenshots below:-

test1.png

test2.png

2. Once the Assignee has been selected, the User Picker field will be updated as expected, as shown in the screenshots below:-

test3.png

test4.png

3. Once the User Picker field has been set, even if the Assignee changes, the User Picker field will still retain the first selected Assignee as shown in the screenshot below:-

test5.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

 

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 31, 2023

Hi @Dmitry

Has your question been answered?

If yes please accept the answer.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer