Hi Community,
I have a custom script post-function which creates sub-tasks based on the objects selected in an insight custom field 'Data Sources'; it also sets the Summary of each sub-task as the 'Name' attribute for that insight object. The insight custom field may contain multiple objects and the script iterates through the selected objects creating a sub-task for each.
I also want to set the insight custom field 'Data Sources' in each sub-task with the object that it relates to. I thought that this would be easiest as a post function in the sub-task workflow on the Create transition that would take the Summary and use that to set the 'Data Sources' field (as they will be the same).
However I am struggling and would appreciate any help.
Here is what I have come up with from combining various sources but not quite there. I would really appreciate any help:
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner
import customRiadaLibraries.insightmanager.SimplifiedAttachmentBean
import com.riadalabs.jira.plugins.insight.services.model.*
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule IQLFacade iqlFacade
def summary = issue.getSummary()toString()
/* Insight custom field to set */
CustomField insightCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11700);
/* Get Insight IQL Facade from plugin accessor */
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade");
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass);
/* 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.findObjectsByIQLAndSchema(16, "Name = \"" + summary + "\"");
issue.setCustomFieldValue(insightCF, objects);