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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,560,218
Community Members
 
Community Events
185
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.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade

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

@WithPlugin("com.riadalabs.jira.plugins.insight")

@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" = "chethan.gr"/)[0];

if(objects){

    /* Insight custom field to set */

    def insightCF = ComponentAccessor.customFieldManager.getCustomFieldObject(20001)

    issue.setCustomFieldValue(objects)

    return objects;

}


1 answer

Hi @Chethan GR you can try with IssueService :

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

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.

 

Regards,

Chethan

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

https://insight-javadoc.riada.io/insight-javadoc-5.0/com/riadalabs/jira/plugins/insight/services/model/ObjectBean.html#getObjectKey--


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
TAGS
AUG Leaders

Atlassian Community Events