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

Update Insight Custom field => cannot be cast to java.util.Collection'



i have a strange problem. My script is practically finished.

To understand the script : In Insight, i have all our servers object created automatically. 

We use a monitoring called Centreon, this monitoring send an email to the service desk mailbox automatically when a error occur and a ticket is created. I want to add the corresponding object to the corresponding server.

The name of the server is present in the summay of the email;

Example : problem alert

A groovy script check the name of the server, if it found a correspond name (in the FQDN Attribute), the object is affected to the ticket. 

All code working until the updating of the ticket, i have a statement where all objects are checked, when i found the good object (string currentobject), i want to update the current issue with this object i have the error : 

GroovyInsightException: cannot be cast to java.util.Collection'


BUT if i replace currentobject by Objects (i suppose it's an array), the ticket is updating with all objects without any error. I understand that a i can only update the ticket with an array and not a unique value... I don't found the good way to do it... Thank you for your help.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import groovy.transform.ToString

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);

//CustomField jiraCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12124);

CustomField insightCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12124);

Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);

def objects = iqlFacade.findObjectsByIQLAndSchema(10,"objectTypeId = 2443");
//def test = "AF-172738"
//def ObjectInsightBean = objectFacade.loadObjectBean(test)
//log.warn("ObjectInsightBean " + ObjectInsightBean)
def n = 0
(objects).each {
CurrentObject = objects[n]
def fqdnvalue = objectFacade.loadObjectAttributeBean(CurrentObject.getId(),47464).getObjectAttributeValueBeans()[0]; //Load Attribute Value

def fqdn_string = fqdnvalue.toString()
def fqdn_string_split = fqdn_string.split("\\(");
def fqdn_string_split_1 = fqdn_string_split[1]
def fqdn_string_split_2 = fqdn_string_split_1.substring(0, fqdn_string_split_1.length() - 2);

result = (issue.getSummary().contains(fqdn_string_split_2)) // if the value fqdn_string_split_2 present in the summary => result = true
if (result==true){"Statement " + "True" + CurrentObject);
MutableIssue mi = (MutableIssue) issue;
mi.setCustomFieldValue(insightCF, CurrentObject); // => Work if i replace CurrentObject by objects
ComponentAccessor.getIssueManager().updateIssue(currentUser, mi, EventDispatchOption.DO_NOT_DISPATCH, false); // Error GroovyInsightException: cannot be cast to java.util.Collection'

}"fqdn_string_split_2 " + fqdn_string_split_2)"Result " + result)
n ++
return result;


1 answer

1 accepted

0 votes
Answer accepted

Solved by using : def CurrentObject_list = [CurrentObject];

(converted into list) 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

339 views 3 14
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