Jira Post Functions Groovy Script Error

hi, All


If I select the "Select List (Multiple Choice)" field value
I want to automatically enter the USER ID in the "User Picker (Multiple Choice)" field.



Product (Multiple Select Field) - Smart FA  (Value)

                                                   TBD (Value)

                                                   Venus (Value)

People (Multiple User Choice Field)


If "Product" -> "Smart FA" is selected, I want to have UserID automatically input in the People Field.

So I wrote the following script.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.user.util.UserUtil

def componentManager = ComponentAccessor.getUserManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField multi = customFieldManager.getCustomFieldObject("customfield_id" -> Product Field)
def options = issue.getCustomFieldValue(multi) as List<Option>

if (!options){
// No element is selected

if(options*.value.containsAll("Smart FA")) { 

CustomField person = customFieldManager.getCustomFieldObject("customfield_id" -> People Field)
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
person.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(person), ["USER_ID"]), changeHolder)


However, the following error occurs.

java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.user.ApplicationUser
	at com.burningcode.jira.issue.customfields.impl.WatcherFieldType.getChangelogValue(WatcherFieldType.java:235)
	at com.burningcode.jira.issue.customfields.impl.WatcherFieldType.getChangelogValue(WatcherFieldType.java:80)
	at com.atlassian.jira.issue.fields.CustomFieldImpl.getChangelogValue(CustomFieldImpl.java:432)
	at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:494)
	at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:454)
	at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)
	at Script394.run(Script394.groovy:35)


What's wrong with Script?
Please help me.



1 answer

1 accepted

1 vote
Vasiliy Zverev Community Champion Dec 06, 2016

Here should be an Application user but not a String:

person.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(person),/*Here Application user is requred*/ ["USER_ID"]), changeHolder)

Thank you for answer.
It was helpful.

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 Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

118 views 0 5
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