Edit: It turns out that I wasn't doing anything wrong. This is simply the nature of Forms and Jira. The value isn't written to the custom field until well after the ticket is created.
The solution is to put your Groovy code in a listener, instead of as part of a workflow transition.
I wrote a little explanation for anyone who needs it:
https://www.kennethmcclean.com/blog/the-forest-for-the-trees-custom-field-null-values-during-workflow-transitions/
****************************************
We have a groovy script that takes the value stored in a custom field on a ProForma form(the field is a single-user picker).
On create the script should move that value to a different field (and does a bunch of other things).
However it fails every time, as Jira insists that the initial value of the custom field is null.
If we set the script to run on any transition after create, it works fine. The script also works fine on existing tickets, using the Scriptrunner Console.
It’s as though the value of the custom field is not being set until well after the create transition has finished.
I simplified the script to just grabbing the value stored in the custom field, and logging still returns null.
Is there a way to ensure that the custom field value populates during the create transition?
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
log.setLevel(Level.DEBUG)
UserManager usrMgr = ComponentAccessor.getUserManager()
CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager()
CustomField lobCf = cfMgr.getCustomFieldObject("customfield_12345")
log.debug "customfield value is"+ issue.getCustomFieldValue(lobCf)
Hi @Kenneth McClean - Pete from the ProForma team here. Due to the order of events, it’s common for this kind of automation to read null data from ProForma. I know this can be avoided in ScriptRunner by adding a sleep() call to the beginning of the script to give enough time for ProForma data to save to Jira. I’m not as familiar with groovy, but think a similar approach could work.
Hi Pete:
Thank you very much for your answer. I'll give the sleep call a try.
Cheers,
Ken
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter PrestonI tried adding a sleep() of up to 15 seconds at the start of my script. It certainly delayed the running but it didn't seem to make a difference otherwise. Is there anything else I need to do to make this work? I tried sticking the sleep call in different places in my script.
Thanks!
Ken
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kenneth McClean -- hmm. I've asked around and don't have a great answer for you at the moment. I suggest connecting with support.thinktilt.com and seeing they can shed more light on the order of operations.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.