Trying to set a customfield value to a string/username based on other customfield value


I am using the below Custom script post-function script, to set a custom field(i,e Test Managers) value to a string (i,e rrahul). But not working and getting the below ERROR, but script looks fine.

2016-11-28 16:53:45,682 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-11-28 16:53:45,683 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INT-1583, actionId: 131, file: <inline script>
groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script368

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import java.sql.Timestamp
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def cf = customFieldManager.getCustomFieldObjects(issue).find { == 'Defect Source'}
def cfgvalue = issue.getCustomFieldValue(cf)
if (cfgvalue == "ITG" || "MTG")
def cf1 = customFieldManager.getCustomFieldObjects(issue).find { == 'Test Managers'}
def newvalue = "rrahul"   //user id name of a test manager
issue.setCustomFieldValue(cf1, newvalue)

1 answer

1 vote

Your script is missing the acquisition/creation of the custom field manager object.

Try adding this after the imports

def customFieldManager = ComponentAccessor.getCustomFieldManager()

I suspect you're going to have problems with the setCustomFieldValue call as well - you are giving it a string, where it needs a user object.


Thanks Nic for your prompt feedback.

After adding the above import, I am not seeing the error which I posted before.

But while doing transition itself, I am getting the below error now::

Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: java.lang.String cannot be cast to java.util.Collection

post successful transition only, I will able to check the set custom field value of i,e Test Managers as rrahul set successfully or not.

Please re-read the last sentence of my answer.  You may also need to do it as an array of users too, if the field is multi-user.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


275 views 0 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you