Hello,
I have created a single user type custom field that I would like to be hidden from users (whether it's through not placing on any screens, or writing a behavior script to hide the field from all users).
I am attempting to create a post function on the "Create Issue" transition and "PCR Transition" to set the value of that custom field. Another post function script may use this custom field as an email recipient.
The value is coming from a scripted field.
This is what I have:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.user.ApplicationUser
log.setLevel(Level.DEBUG)
//Grab necessary Components
def cfm = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def proSE = cfm.getCustomFieldObjectByName("Service Executive")
log.info("Pro Service Executive object: " + proSE)
ApplicationUser user = (ApplicationUser)issue.getCustomFieldValue(proSE)
def userName = user.getName()
log.info("Pro Service Executive user: " + userName)
//Set custom text field
def hiddenSE = cfm.getCustomFieldObjectByName("Hidden Service Executive")
log.info("Hidden Service Executive object: " + hiddenSE)
issue.setCustomFieldValue(hiddenSE, userName)
log.info("Hidden Service Executive: " + hiddenSE.getValue(issue))
The logs read the following:
2019-02-05 11:25:39,224 INFO [workflow.ScriptWorkflowFunction]: Pro Service Executive: Service Executive 2019-02-05 11:25:39,224 INFO [workflow.ScriptWorkflowFunction]: Pro Service Executive user: sthomson 2019-02-05 11:25:39,224 INFO [workflow.ScriptWorkflowFunction]: Hidden Service Executive object: Hidden Service Executive 2019-02-05 11:25:39,224 INFO [workflow.ScriptWorkflowFunction]: Hidden Service Executive: null
The username "sthomson" is a real user in my JIRA instance. I have hard-coded that username in other scripts and it has worked. The problem seems to be the function call `issue.setCustomFieldValue()`. Is there some kind of casting that I need to do on `userName`?
Any help would be greatly appreciated.
Hello,
Can you please try cating to MutableIssue before updating?
MutableIssue missue = (MutableIssue) issue
missue.setCustomFieldValue(hiddenSE, userName)
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.