Unable to Set Single User Custom Field via post function.

Edward Greathouse February 5, 2019

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.

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 5, 2019

Hello,

Can you please try cating to MutableIssue before updating?

MutableIssue missue = (MutableIssue) issue
missue.setCustomFieldValue(hiddenSE, userName)

Suggest an answer

Log in or Sign up to answer