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;
}
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def objects = iqlFacade.findObjects(8, /objectType = "Computer" and "Assigned User" = "chethan.gr"/)[0]
From your code above, the key of insight object already dynamic
def keyOfInsight = objects.getObjectKey()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.