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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Problem with groovy and postfunction

Hi,

we have a groovy, that do not work from several weeks:

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.user.util.UserManager;

import com.atlassian.jira.user.ApplicationUser;

import com.atlassian.jira.user.ApplicationUser;

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

import com.atlassian.jira.issue.util.IssueChangeHolder;

import com.atlassian.jira.issue.ModifiedValue;

import com.atlassian.jira.issue.customfields.manager.OptionsManager;

 

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

 

def userManager = ComponentAccessor.getUserManager();

def issueManager = ComponentAccessor.getIssueManager();

 

def jobInterviewerICSD = customFieldManager.getCustomFieldObjectByName("Job Interviewer I CSD");

def jobInterviewerIPBS = customFieldManager.getCustomFieldObjectByName("Job Interviewer I PBS");

 

CustomField privilegesField = customFieldManager.getCustomFieldObjectByName("Access privileges");

 

if(jobInterviewerICSD != null){

               ModifiedValue newPrivilegesField = new ModifiedValue(issue.getCustomFieldValue(privilegesField), jobInterviewerICSD);

               privilegesField.updateValue(null, issue, newPrivilegesField, new DefaultIssueChangeHolder());

               return privilegesField;

}

 

if(jobInterviewerIPBS != null){

               ModifiedValue newPrivilegesField = new ModifiedValue(issue.getCustomFieldValue(privilegesField), jobInterviewerIPBS);

               privilegesField.updateValue(null, issue, newPrivilegesField, new DefaultIssueChangeHolder());

               return privilegesField;

}

 

The postfunction error shows:

 

 

2018-06-15 11:46:45,266 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************

2018-06-15 11:46:45,267 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: REC-19463, actionId: 891, file: /var/atlassian/application-data/jira/scripts/GroovyScripts/recruitnsc/scripts/set_access_privileges.groovy

java.lang.ClassCastException: com.atlassian.jira.issue.fields.ImmutableCustomField cannot be cast to java.util.Collection

      at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)

      at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)

      at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410)

      at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396)

      at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)

      at set_access_privileges.run(set_access_privileges.groovy:25

Do you see any possible errors?

 

Thank you

1 answer

There are several incorrect or improvable things in that script. What are you trying to do here?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

779 views 17 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you