Running this script as a post function
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import org.apache.log4j.Logger
def log = Logger.getLogger("com.acme.workflows")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def eDate = customFieldManager.getCustomFieldObjectByName("End Date")
def eDatev = issue.getCustomFieldValue(eDate)
if ( eDatev == null )
{ log.warn "End Date is set to " + eDatev def sDate = customFieldManager.getCustomFieldObjectByName("Implementation Date") def sDatev = issue.getCustomFieldValue(sDate) log.warn "Implementation Date is set to " + sDatev issue.setCustomFieldValue( eDate, sDatev) }
eDatev = issue.getCustomFieldValue(eDate)
log.warn "End Date is set to " + eDatev
The log file reads
2019-03-15 11:14:58,980 WARN [acme.workflows]: End Date is set to null
2019-03-15 11:14:58,980 WARN [acme.workflows]: Implementation Date is set to 2019-03-20 00:00:00.0
2019-03-15 11:14:58,980 WARN [acme.workflows]: End Date is set to 2019-03-20 00:00:00.0
This shows the End Date is changed, as expected. But the value isn't saved. I have found this reference
It seems to suggest that the value will be saved. It is the 2nd item in a post function
What am I missing?
Hello @Roy Chapman
The value is not changing because you are not doing it right.
You are using
issue.setCustomFieldValue( eDate, sDatev) }
From the docs about this method
Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading.
PLease see this example for the basic method to update the custom field for a issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you. I have amended the script and added these lines
(I have also done a bit of tidying up, but want to retain the thread in case someone else have the same issue)
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def changeHolder = new DefaultIssueChangeHolder()
def eDatec = customFieldManager.getCustomFieldObjects(issue).find {it.name == "End Date"}
eDatec.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(eDatec), eDatev),changeHolder)
Works a treat now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Maybe try to add this code at the end :
import com.atlassian.jira.issue.index.IssueIndexingService
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)
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.