Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Manjunatha K R
Contributor
November 28, 2016

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
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 28, 2016

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.

 

Manjunatha K R
Contributor
November 28, 2016

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.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 28, 2016

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
TAGS
AUG Leaders

Atlassian Community Events