Update Custom Field Value using a "Scriptrunner for Jira" Custom Listener
<p>Hello we are using Jira and are currently evaluating the Plugin "Scriptrunner for Jira" by Adaptavist.</p>

<p>I'd like to create a custom Listener which simply updates the value of a custom field. The field's type is a default textbox, nothing fancy there.</p>

<p>Regarding to the plugin's documentation and various web-searching, I came up with the following code:</p>

<pre><code>import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as Issue
MutableIssue issueToUpdate = (MutableIssue) issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'My CustomField'}
issueToUpdate.setCustomFieldValue(cf, "myvalue");
</code></pre>

<p>The validator does not complain about anything here and the script seems to be executed without any errors. The problem is that the custom field's value is simply not updated. Maybe some of you guys have the missing piece.</p>

<p>Every line seems to be needed as the validator complains otherwise. Thank you in advance for your help.</p>