I was trying to use singleline_field.updateValue(null, issue, new ModifiedValue("", (Object) desiredValue), new DefaultIssueChangeHolder()) and issue.setCustomFieldValue(singleline_field, "desiredValue") - both functions do not seem to work if target field is hidden on the screen (this is mandatory because readonly custom fields do not exist in Jira).
Also I'm getting an error below when trying to update Multiple Users field value with array of users
Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> java.lang.ClassCastException: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to com.riadalabs.jira.plugins.insight.services.model.ObjectBean
What are possible solutions?
Hi
Have you tried to use updateIssue function instead of updateValue or setCustomFieldValue?
Yes, I've tried the updateIssue function
I believe it gives the exact same result as setCustomFieldValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Hmmm... from your error looks like you are using different types of variables.
I've created small code in built-in scripts console and it works- I am able to update multiple users field. Try something like this:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def componentManager = ComponentManager.getInstance();
def optionsManager = ComponentAccessor.getOptionsManager();
UserManager userManager = ComponentAccessor.getUserManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
def result='initial';
Issue iss = issueManager.getIssueObject('<issue Key>');
MutableIssue issueToUpdate = (MutableIssue) iss;
def cfield = customFieldManager.getCustomFieldObject('<Long fieldID>');
def fieldConfig = cfield.getRelevantConfig(issueToUpdate);
def allOptions = optionsManager.getOptions(fieldConfig)
ApplicationUser user1 = userManager.getUserByKey('<username>');
ApplicationUser user2 = userManager.getUserByKey('<username>');
List<ApplicationUser> userlist = new ArrayList<ApplicationUser>()
userlist.add(user1);
userlist.add(user2);
issueToUpdate.setCustomFieldValue(cfield, userlist);
issueManager.updateIssue(currentUser, issueToUpdate, EventDispatchOption.ISSUE_UPDATED, false);
result=cfield.toString();
return result;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.