Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Insight customField update in Scriptrunner


Hi, I am not able to update Insight CustomField in Jira using Script listener


On their site, you can find this link:

When I am running it in console, everything works, but when I try to use the same code as the Listener, there is problem with this part:

def objects = iqlFacade.findObjectsByIQLAndSchema(1, "Name = \"" + workstationName + "\"");


When working as Listener, above code return 0 results. The same IQL works in Jira and in console

3 answers

1 vote

Hi, thanks for suggestion. I will try to change user to a person who do have access. Meantime I am pasting my code (this is a bit messy). 

In console, instead of trying to use captured issue upon "New issue creation event" I am just using some example issue.

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.fields.CustomField;;
import java.util.regex.*;
import com.atlassian.jira.issue.util.*;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.bc.issue.*;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.component.*;
import com.atlassian.jira.issue.IssueImpl.*;
import com.atlassian.jira.event.type.EventDispatchOption;

def issueManager = ComponentAccessor.getIssueManager();
Issue issue = issue;
if(issue.getIssueTypeId() == '10600'){
String Description = issue.getDescription().toString();
String description;
String workstation;
def Label = issueManager.getIssueObject("IT-390").getLabels();
MutableIssue iss = issue;
Pattern pattern = Pattern.compile("\\w{3}\\d{5}\\w");
Matcher matcher = pattern.matcher(Description);
while (matcher.find()){
workstation =;
pattern = Pattern.compile("What happened: (.*)");
matcher = pattern.matcher(Description);
while (matcher.find()){
description =;
def changeHolder = new DefaultIssueChangeHolder()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueDescription = customFieldManager.getCustomFieldObject("customfield_11101");
issueDescription.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(issueDescription), description), changeHolder);
def pc = customFieldManager.getCustomFieldObject("customfield_11100");
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);
String iql = "Name = \"" + workstation + "\""
def objects = iqlFacade.findObjectsByIQLAndSchema(3, "Name = \"" + workstation + "\"");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
if (objects) {
MutableIssue mi = (MutableIssue) issue;
mi.setCustomFieldValue(pc, objects);
ComponentAccessor.getIssueManager().updateIssue(user, mi, EventDispatchOption.DO_NOT_DISPATCH, false);
} else {
log.error("There is no such an object")
} catch (Exception e){
log.error("Wrong iql")

Matcher is catching the name of the workstation from Description, and I can confirm it is working correctly. After I run IQL search, objects variable is empty.


Example log than I have from code above:

2020-08-19 09:32:46,828 ERROR [runner.ScriptBindingsManager]: 10600
2020-08-19 09:32:46,844 ERROR [runner.ScriptBindingsManager]: [Sophos]
2020-08-19 09:32:46,857 ERROR [runner.ScriptBindingsManager]: PPL20032L
2020-08-19 09:32:46,875 ERROR [runner.ScriptBindingsManager]: Name = "PPL20032L"
2020-08-19 09:32:46,954 ERROR [runner.ScriptBindingsManager]: []
2020-08-19 09:32:46,954 ERROR [runner.ScriptBindingsManager]: There is no such an object

So, user is catched after iql method, so that didn't help. I cannot perform update on empty object.

Hi Damian,

the problem is definitely in the search part. I've tested the code below ("validate IQL and find object with name "Test" in object schema 1 in Insight").

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl.*

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

final String objectName = "Test"
final int objectSchemaId = 1

String iql = "Name = \"" + objectName + "\""
try {
def objects = iqlFacade.findObjectsByIQLAndSchema(objectSchemaId, iql)
if (objects) {
} else {
log.error("There is no such an object")
} catch (Exception e){
log.error("Wrong iql")

It works for me in console and also as a listener code.

I'm not able to find the objects, when I limit the access to Insight scheme for the user, who creates the issue (then the Issue created event is fired and the listener code is executed).

In your code, the user object is used for the issue update operation, but this is not important. I think the problem is with the user, who performs the search in Insight - I believe the user, who creates the issue, is the one who is used for the search operation. When you use this code in console, search is performed by your user, so it works.

Is it possible explanation? Who does create the issues in your project?

Yeah I understand what you suggest. I have mail handler to create tickets, I added the reporter to the Insight but it does not work. I am not sure if reporter is the one who is creating it, or maybe there is some generic user that performs those actions.


For now it is not working, even when I added the reporter to Insight, I will try to check which user is used to create issues.



any chance someone could modify the script from the Insight documentation to copy the values in a labels field to an insight field?


I'm currently doing it by sending tickets through an insight post function on a global transition, but that triggers the issue updated event which spews old tickets back onto peoples boards :( As far as I'm aware when you do these edits via scriptrunner it doesnt trigger the issue updated event.

0 votes
Deleted user Jul 08, 2021

Run the script as an user with insight access by:

ApplicationUser superuser = userManager.getUserByName("superuser")
0 votes
Hana Kučerová Community Leader Aug 20, 2020

Hi @Damian Wodzinski ,

could it be, that the script is somehow affected by the user, who executes the script?

Are there any users, who are not able to view the objects in Insight?

Would you please provide me the whole code? I'll try to test it using my instance.

Which versions of Jira/ScriptRunner/Insight do you have?

Thank you.

I posted code below, 

Jira version: 8.4.1
ScriptRunner version:  6.6.0 
Insight version:  8.6.4 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events