Groovy script for adding watchers based on custom field value

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

This widget could not be displayed.

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()
This widget could not be displayed.

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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

199 views 1 3
Join discussion

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