Forums

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

get linked date/time with scriptrunner

Kevin Dalton
Contributor
March 6, 2018

We are trying to set a custom field(date/time) when an issue is linked with a certain link type direction but only to a certain project.  Is there a way to get the created date/time from the history when the issue is linked?

 

Here is what I have so far but it returns null.  if i remove the contains i end up getting all linked history fro the issue.

 

{code}

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

Issue issue = issue

IssueManager issueManager = ComponentAccessor.getIssueManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHolder = new DefaultIssueChangeHolder()


log.debug "testing"
def time = changeHistoryManager.getChangeItemsForField(issue, "Link").collect { it.to.contains("PC-") }
log.debug(time)

{code}

2 answers

2 accepted

2 votes
Answer accepted
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2018

Hi Kevin,

Try this:

chgHistMgr.getChangeItemsForField(issue, "Link").findAll{it.getTo().contains("PC-")}.collect{it.getCreated()}

This'll return an array of Timestamp objects, each of which represents the time when your issue has been linked to a "PC-...." issue. After that you can use an element from this array (a timestamp object in this case) to populate your date custom field.

Hope this helps.

0 votes
Answer accepted
Kevin Dalton
Contributor
March 6, 2018

Thanks Ivan here what i ended up using

 

if (! PPMTSDvalue && issue.issueType.name == "Epic") {

log.debug "testing"
List <ChangeItemBean> changeItems
changeItems = changeHistoryManager.getChangeItemsForField(issue, "Link")
def time = changeItems.findAll{it.getToString()?.contains("is a child of")}?.collect{it.getCreated()}.last()
log.debug(time)

PPMTSD.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(PPMTSD), time),changeHolder)
}

Suggest an answer

Log in or Sign up to answer