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;
}