We have a Script Listener that updates fields but doesn't update the History of the Issue. Per Payne on an earlier question "...EVERY change (except comments and changes to comments) SHOULD be recorded in the History tab."
This is a snippet of the Groovy code:
---------------------------------------------------------------------------------------
/*
* Fires when a Issue Link is created.
* Exits if Linked to Issue is not Initiative / Feature / Epic
* Copies Custom Fields down from Linked Issue
*/
// imports...
// Setup Custom Field Manager
def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
// Grab Event
def event = event as IssueLinkCreatedEvent
// sourceIssue is really the Issue that is being Linked to.
def sourceIssue = event.getIssueLink().getSourceObject()
log.info("sourceIssue: " + sourceIssue.key)
// Exit if not Initiative / Feature / Epic
if (sourceIssue.issueType.name != "Epic" &&
sourceIssue.issueType.name != "Feature" &&
sourceIssue.issueType.name != "Initiative") {
log.info("Exiting ... sourceIssue type of: " + sourceIssue.issueType.name + " is not Epic / Feature / Initiative")
return 0
}
// Which makes the Destination object really the issue
def issue = event.getIssueLink().getDestinationObject()
log.info("issue: " + issue.key)
/**
* Workfront Project
*/
def CfWorkFrontProject = CustomFieldManager.getCustomFieldObject('customfield_10703')
log.info("CfWorkFrontProject")
// Copy if target Field IS Empty and source field is NOT Emtpy
if(!issue.getCustomFieldValue(CfWorkFrontProject) &&
sourceIssue.getCustomFieldValue(CfWorkFrontProject)
) {
def oldData = issue.getCustomFieldValue(CfWorkFrontProject)
def newData = sourceIssue.getCustomFieldValue(CfWorkFrontProject)
CfWorkFrontProject.updateValue(null, issue, new ModifiedValue(oldData, newData), new DefaultIssueChangeHolder());
log.info("Workfront Project updated to: " + newData)
} else {
log.info ("Not CfWorkFrontProject && not value in CfWorkFrontProject")
}
return
---------------------------------------------------------------------------------------
When the listener is triggered, it does update the CfWorkFrontProject field but there's no corresponding log entry and we have no clue why.
Are we updating custom fields incorrectly?
My colleague and I are very new to Jira/ScriptRunner/Groovy and so may be writing some very offensive code. For that we apologize.
Hi @Bruce Mohler ,
You can use this code to have the update display in the history :
import com.atlassian.jira.event.type.*
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def sendMail = true
int cfId = 13401
def cfObject = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(cfId)
def cfNewValue = ....
issue.setCustomFieldValue(cfObject, cfNewValue)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, sendMail)
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Antoine, we have some scripts which are using the IssueService rather than the IssueManager to change the values of custom fields (and they're not updating History either).
We're not really clear what the canonical way to update these fields is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry , when I paste those lines into the Script Console, the following 2 lines generate syntax errors:
def cfObject = getCustFieldObjectById(cfId)
issue.setCustomFieldValue(cfObject, cfNewValue)
The first can't find a method that accepts an int as an argument.
The second can't find a method that accepts an Object and String as arguments.
I'm a bit baffled. I'm not sure whether I'm missing an import or 2? I tried to search Google for getCustFieldObjectById (hoping to land in the Atlassian API documentation) but it kept trying to send me to another method (getCustomFieldObjectByName).
Suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bruce Mohler ,
I am terribly sorry, that is a custom method I am using and forgot to replace it. I updated the original answer with the correct code. It should work now if the cfNewValue fits to the custom field type.
IssueService is AFAIK the best way to update as you can check if the field can correctly be updated, so you can use that as well.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bruce Mohler , did that work for you ? In that case please make sure to accept the answer so it can help others in the future.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately it seems not to work for me. The field is updated but I have no change visible in the history :-(
Also an IssueUpdated event isn't triggered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Finally I have come to a working solution based on the issueService. I have shared my learnings here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.