Hello
I like to get the value of custom field User Picker (single). The value cfVal allways is null.
This example I was searching and found many times, but can't solve the problem.
import com.atlassian.jira.component.ComponentAccessor;
def cf = customFieldManager.getCustomFieldObject("customfield_11501")
def cfVal = issue.getCustomFieldValue(cf)
def check = "cf: " + cf + " / cfVal: " + cfVal
issue.setDescription(check)
Problem solved!
By cloning an Isssue Issue.getCustomFieldValue() points to target issue
Hi @Tom
I have run a basic test in my environment and don't seem to be encountering any issues.
Below is the sample code that I have tested with:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def sampleUserPicker = customFieldManager.getCustomFieldObjectsByName('Sample User Picker').first()
def sampleUserPickerValue = issue.getCustomFieldValue(sampleUserPicker).toString()
def check = "cf: ${sampleUserPicker} / cfVal: ${sampleUserPickerValue}"
issue.setDescription(check)
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Post-Function configuration:-
Below are a couple of test screenshots:-
1. First, the Description field is set to blank when the Issue is created. Also, you will notice that a Custom Field called Sample User Picker is filled with the Admin user.
2. Once the Issue transitions to the In Progress status, the Description field is updated with the values set in the code.
Regarding why you are getting the Null value, I suspect the value for the User Picker field has not been set yet. (I could be wrong)
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Welcome to the community
I think this script should do the work
import com.atlassian.jira.component.ComponentAccessor;
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("yourIssueKey")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_11501")
def cfVal = issue.getCustomFieldValue(cf)
log.warn(cfVal.displayName)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see, so you can use 'issue' like you first script to get the current issue.
import com.atlassian.jira.component.ComponentAccessor;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_11501")
def cfVal = issue.getCustomFieldValue(cf)
log.warn(cfVal.displayName)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this case cfVal is NULL. I tried to add
import com.atlassian.jira.issue.Issue;
def issueKey = issue.getKey()
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.