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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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

Need help with the script to populate the data in insight objects field

Chethan GR
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.
Oct 20, 2022

We have a requirement to populate the value in an insight field on the create screen on the portal when the users open the form.


We have an insight objects field which shows the computer objects that are owned by the logged in user and currently the user has to select the value from the dropdown but we want to auto populate the value instead of user having to select it. I'm using the below script but the value is not getting populated.


import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.onresolve.scriptrunner.runner.customisers.WithPlugin


import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.component.ComponentAccessor

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


@PluginModule IQLFacade iqlFacade

def issue = Issue

def groupManager = ComponentAccessor.getGroupManager()

def formField = getFieldById(getFieldChanged())

// def Reporter = issue.getReporter()

/* Specify the schema id as well as the IQL that will fetch objects. In this case all objects with Name matching the valueCF, be sure to include " around value */

def objects = iqlFacade.findObjects(8, /objectType = "Computer" and "Assigned User" = ""/)[0];


    /* Insight custom field to set */

    def insightCF = ComponentAccessor.customFieldManager.getCustomFieldObject(20001)


    return objects;


1 answer

Hi @Chethan GR you can try with IssueService :

IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();

inputParameters.addCustomFieldValue(insightFieldId, "Key of insight object you want to populate");
UpdateValidationResult updateValidationResult = issueService.validateUpdate(ItsmUtils.getItsmUser(), targetedIssue.getId(), inputParameters);
if (updateValidationResult.isValid()) {
issueService.update(user, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, true);
} else {
log("Error when update custom field value in " + targetedIssue.getKey() + " " + updateValidationResult.getErrorCollection().toString());

 Hope it's can you, note "User" must have permission to perform an update on the issue and the value to update is the key of insight object

Chethan GR
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.
Jan 09, 2023

Hi @Hieu ,


Thanks for the response.


As the computer objects will have unique keys and providing the key would become a hardcoded value!


The need is to automatically populate the user's computer as they open the form. And we need to populate this when the user has only one computer and if there are many then we can ignore.




def objects = iqlFacade.findObjects(8/objectType = "Computer" and "Assigned User" = ""/)[0]

From your code above, the key of insight object already dynamic 

def keyOfInsight = objects.getObjectKey()

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events