Groovy script for adding watchers based on custom field value

Neil Taylor April 6, 2015

Hello

I am working on a script to add watchers to an issue on creation based on a custom field value.  I am using this on a multi select field, so ideally it would add watchers for each selection in the multi select field

 

Script (part of it that seems to be getting caught in errors):

MutableIssue mutableIssue = (MutableIssue) issue;

def application = mutableIssue.getCustomFieldValue('customfield_12610');

 

    if(application.equals("BL")){

        watchUsers(BL_users);

    }

    if(application.equals("FOC")){

        watchUsers(FOC_users);

}

 

Error:

2015-04-06 08:51:47,604 http-bio-8080-exec-12 WARN neiltaylor 531x2689x1 1ur03l5 12.97.73.94 /secure/QuickCreateIssue.jspa [onresolve.scriptrunner.runner.ScriptRunnerImpl] Add a script root for this path: C:\NGP\scripts\groovy\DPL.groovy

2015-04-06 08:51:48,057 http-bio-8080-exec-12 ERROR neiltaylor 531x2689x1 1ur03l5 12.97.73.94 /secure/QuickCreateIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************

2015-04-06 08:51:48,057 http-bio-8080-exec-12 ERROR neiltaylor 531x2689x1 1ur03l5 12.97.73.94 /secure/QuickCreateIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: DPL-2725, actionId: 1, file: C:\NGP\scripts\groovy\DPL.groovy

javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [customfield_12610]

Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)

    at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runFileAsScript(ScriptRunnerImpl.groovy:195)

    at com.onresolve.scriptrunner.runner.ScriptRunner$runFileAsScript$4.call(Unknown Source)

    at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:47)

    at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript$2.call(Unknown Source)

    at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.doScript(CustomScriptFunction.groovy:20)

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [customfield_12610]

Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)

    ... 5 more

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [customfield_12610]

Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)

    at com.onresolve.jira.groovy.canned.workflow.postfunctions.Script3.run(Script3.groovy:42)

2 answers

1 vote
Andreas Ebert
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.
April 6, 2015

I'm guessing your asking why you get that error? (You didn't state it clearly). Here's why:

You wrote mutableIssue.getCustomFieldValue('customfield_12610'), but MutableIssue (or better: Its implementation IssueImpl) does not have such a method which accepts a custom field id as a String. Groovy even tells you what method you should use instead:

Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

You have to give the CustomField object as the argument, not just its id. To get such an object, use the CustomFieldManager:

  • CustomFieldManager#getCustomFieldObject(String)
  • or CustomFieldManager#getCustomFieldObject(Long)
  • or CustomFieldManager#getCustomFieldObjectByName()
0 votes
Dustin Chamberlain November 6, 2015

Any way to know what this script should look like for a single field value?

Suggest an answer

Log in or Sign up to answer