Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

customField.update() not writing to history / activity log, Edited

I am using a listener script to copy a custom field value from parent to child issues.

Here the script is working as expected but customfield changes made by the listener were not getting captured under Issue History tab 

import com.atlassian.jira.util.ComponentLocator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHistory = changeHistoryManager.getAllChangeItems(issue).each{
}
def chHistory = changeHistory[-1].field.toString()
final cf = 'customfieldname'
def issue = event.issue
def change = event.changeLog.getRelated('ChildChangeItem').find { it.field == cf }
if (!change) {
    return
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll {it.issueLinkType.name in ['Epic-Story Link'] }
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.find {it.name == cf}
def nV = change.newstring
linkedIssues.each{
    def linkedIssue = it.destinationObject
    def oV = linkedIssue.getCustomFieldValue(customField)
    customField.updateValue(null, linkedIssue, new ModifiedValue(oV, nV), new DefaultIssueChangeHolder())
}

I heard that updateValue method will not log into the history. Is there any alternative solution/fix?

Am I doing anything wrong?

1 answer

1 accepted

0 votes
Answer accepted

Hello Uday,

Try using IssueManager. See this Atlassian Community post for more details.

Regards,

Hyrum

@Hyrum Steffensen  Hello,

Thanks for your suggestion. I have tried IssueManager but it doesn't seem like work

Here is the updated script, I was doing something wrong here. 

 

import com.atlassian.jira.util.ComponentLocator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeHistory = changeHistoryManager.getAllChangeItems(issue).each{
}
def chHistory = changeHistory[-1].field.toString()
final cf = 'customfieldname'
def issue = event.issue
def change = event.changeLog.getRelated('ChildChangeItem').find { it.field == cf }
if (!change) {
return
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll {it.issueLinkType.name in ['Epic-Story Link'] }
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.find {it.name == cf}
def nV = change.newstring
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
linkedIssues.setCustomFieldValue(customField, user){
def linkedIssue = it.destinationObject
def oV = linkedIssue.getCustomFieldValue(customField)
customField.updateValue(null, linkedIssue, new ModifiedValue(oV, nV), new DefaultIssueChangeHolder())
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}

Suggest an answer

Log in or Sign up to answer
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