How do you set a Insight custom field value via ScriptRunner?

I’m trying to create an issue programmatically in a ScriptRunner mail handler.

I managed to create issue, add attachments and set most fields… except a custom Insight field.

Using OptionsManager doesn’t work for the Insight field. So I’m looking at this example:

But Script Editor tells me that it cannot find IQLFacade:

@PluginModule IQLFacade iqlFacade

The facade package exist and this import works:


But there is no IQLFacade class. Has something been changed since that thread?

Calling ComponentAccessor.getPluginAccessor().getClassLoader().findClass() does work on, the class can be found. How come it doesn’t work with WithPlugin/PluginModule and the import?

Edit 2:
Using reflection I managed to parse a string into an insight object (IQL Name = “[String]”) … however, the issue cannot be created due to WorkflowException. If I do not set the insight custom field then everything is fine. So it doesn’t like the value I set, any ideas why?

Edit 3:
So I need to call ObjectFacade.loadObjectBean(id), where id comes from the object returned by IQLFacade. And then I need to wrap the object bean in a list, and set that to the custom field. Then it works.

So now my remaining question is: Why Script Editor cannot resolve IQLFacade class.

I don’t really have any answers for you but I gave up on trying to wrap the Insight API myself and am instead relying on GitHub - Riada-AB/InsightManager: A simplified wrapper for the Insight Java API << this script for integrations with Insight. I found the API obtuse to work with and this script does a good job of hiding the bullshit.

1 Like

I found the problem.

My code has two @WithPlugin statements. There can only be one, instead of a string pass it an array of string to load multiple plugins.

Then the import statements for Insight will work.

1 Like