Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

Scriptrunner Assignee History in a Scripted Field Edited

Assignment history is extremely important to my customer. For some obvious transparency and traceability reasons this is something they want to be able to track. In the past, I've created various "position/title" user picker fields, but that doesn't quite fit the desired functionality. 

Then I saw this in the Adaptavist Library: Show Assignee History on Issue Details Page https://library.adaptavist.com/entity/show-assignee-history-on-issue-details-page 

I wish I had a screenshot to show what the ScriptRunner script fragment produces, but this is what it resembles (Credit: PowerPoint Magic): 

assignee_history_script-fragment-example.png

This script is great! My customer LOVES the simplistic solution.

The down-side to having the script fragment (for my customer) is the following:

  1. It cannot back-date... all precluding history changes are not captured so for pre-existing projects, the assignee history is incomplete.
    • I assume this has to do with the fragment acting like a counter for a specific event.
    • This leads me to concerns about how this information is retained, and what would happen if the system crashed, how is the data stored, and how taxing is it on the system memory? 
  2.  There is no simple way to query against the data as a script-fragment. 
    •  At least not for the average user, I'm sure you can with JQL functions. 
  3.  There is no way to aggregate or export the values.
    •  Script-fragments don't export, not even when exporting to print. 

It's got me wanting to aggregate this in a scripted field... 

Problem is...

  • First, I'm not sure what the most efficient and sustainable way to do this is, AND
  • Second, I'm not sure how to modify the script to have it append the assignee history in a scripted field. 
  •  I think it might be accomplished with a listener and scripted-field combination.
  • I'm also concerned about having multiple values, and how to keep them separate, and meet the customer needs (let's be honest, "wants") listed above. 

I'm open to suggestions, but I am limited within my strict environment. Buying a new add-on(s) is not an option till next FY quarter (if then). 

---

I have a feeling, someone in the community has this same ask/question, and I think it could be accomplished in several ways. I'm about to go down this rabbit-hole, but if anyone has suggestions or has already come up with this solution, I'd be extremely grateful!

1 comment

Hi, I tried the Show Assignee History on Issue Details Page script and it only shows me the previous assignee and not a list of all the assignees. How did you make the whole list appear?

@Z B, That is the first of my listed concerns above. The list generated from the script-fragment does not back-date. Where you set the limit in the code is shown in the image attached below, but it only captures assignee history from the moment you apply the script-fragment. I assume you can change the limit to include more than 5, and I have not tested it to see how many can be listed before the list becomes excessive.

assignee_history_script-fragment-counter.png

As far as to how I did it in my original post... I do not have a Jira environment on this network, so I created the reference image out of various images I found by performing a internet search and splicing them together (via PowerPoint) to resemble what it looks like on my production environment. 

Thanks for the explanation, I understand the question better now.

I was trying to rewrite the table part with StringBuilder builder=new StringBuilder() based on what I found in

 https://community.atlassian.com/t5/Jira-questions/Script-Runner-Last-Login-Date/qaq-p/311789/page/0 

but I'm getting an error for the 29th line: expecting: ':', found: ')' - This is the last ) in the line, I guess.

Do you know how the table could be put into html, or any ideas? My idea was to try to append the new list elements so that the old once wouldn't disappear.

import com.atlassian.jira.avatar.AvatarService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.Issue
import groovy.xml.MarkupBuilder

import java.time.format.DateTimeFormatter
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE

// the upper limited on the assignees to be displayed
final int historyDepth = 50

def issue = context.issue as Issue
def counter = 0

def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def avatarService = ComponentAccessor.getComponent(AvatarService)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

new MarkupBuilder(writer).table {
ComponentAccessor.changeHistoryManager.getChangeHistories(issue).reverseEach {
def changeItems = it.changeItems

if (changeItems.field.first() == ASSIGNEE && changeItems.newstring.first() && counter < historyDepth) {
def user = ComponentAccessor.userManager.getUserByName(changeItems.newvalue[0] as String)
def format = DateTimeFormatter.ofPattern("dd/MMM/yyyy")
def date = it.timePerformed.toLocalDateTime().toLocalDate()
StringBuilder builder=new StringBuilder()
builder.append('<tr><td style="width: 90px;">'+date.format(format)+'</td><td class="jira-user-name user-hover jira-user-avatar jira-user-avatar-small" rel="admin" id="project-vignette_admin" style="margin: 1px 0px 1px 0px; height: 24px;" href="'+$baseUrl/secure/ViewProfile.jspa?name=$user.name+'"><span class="aui-avatar aui-avatar-small"><span class="aui-avatar-inner"><img src="'+avatarService.getAvatarURL(loggedInUser, user)+'"></span></span></td><td>'+user.displayName+'</td></tr>')
/*tr {
td(
style: "width: 90px;", date.format(format)
)
td(
class: "jira-user-name user-hover jira-user-avatar jira-user-avatar-small",
rel : "admin", "id": "project-vignette_admin",
style: "margin: 1px 0px 1px 0px; height: 24px;",
href : "$baseUrl/secure/ViewProfile.jspa?name=$user.name"
) {
span(
class: "aui-avatar aui-avatar-small"
) {
span(
class: "aui-avatar-inner"
) {
img(
src: avatarService.getAvatarURL(loggedInUser, user),
alt: user.name
)
}
}
}
td(
user.displayName
)
}*/
}

counter++
}
}

Also, I changed the final int historyDepth = 50 part and that didn't change anything.

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you