Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner Listener - unable to set hidden field value

Gleb Kartashov
Contributor
August 5, 2019

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? 

1 answer

1 accepted

0 votes
Answer accepted
fjodors
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.
August 6, 2019
Gleb Kartashov
Contributor
August 7, 2019

Yes, I've tried the updateIssue function

I believe it gives the exact same result as setCustomFieldValue

fjodors
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.
August 7, 2019 edited

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;
Like • Gleb Kartashov likes this
Gleb Kartashov
Contributor
August 7, 2019

Thanks for helping me! Will check this out soon

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

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!
AUG Leaders

Upcoming Jira Events