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

Hi,

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
	at Script368.run(Script368.groovy:13)

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 {it.name == 'Defect Source'}
def cfgvalue = issue.getCustomFieldValue(cf)
if (cfgvalue == "ITG" || "MTG")
{
def cf1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == '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: http://confluence.atlassian.com/x/3McB 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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Apr 30, 2018 in Marketplace Apps

Why moving to Confluence Data Center is only a job half-done

Confluence Data Center is a deployment option that was designed for performance at scale. In other words, Confluence will handle increased traffic much reliably in a clustered environment and yo...

229 views 0 6
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