Hello Community,
I do have an issue where I want to get an Insight object's attribute value (Approver, Jira User Object) of a customfield of an issue to put it into a multi user picker. I do have played around with code, but if you might be able to point me to the right direction it would be highly appreciated.
Here is my current code, which does not return the attribute value of the object:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
import org.apache.log4j.Level
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def approverCf = customFieldManager.getCustomFieldObject(10203)
def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
/* 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);
/* Get Insight Object Attribute Facade from plugin accessor */
Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);
/* 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 insightobjects = iqlFacade.findObjectsByIQLAndSchema(3,"objectType = User AND object HAVING inR(\"\",referenceType in (\"approves\"))"); // See the complete list of possible IQL on the Insight Query Language documentation page
/* If this is a mandatory field you should be able to do this: */
log.debug("Assignee: " + issue.assignee)
log.debug("Insight objects: " + insightobjects.each {
println "Item: $it" // `it` is an implicit parameter corresponding to the current element
});
def getInsightAttributeValue(object_id, attribute_id) {
/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
CustomField myCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(object_id) // id of custom field
def objectBean = myCF.getValue(issue)[0]
//return objectBean
return objectFacade.loadObjectAttributeBean(objectBean.getId(), attribute_id).getObjectAttributeValueBeans()[0].getValue() //attribute id
}
if (getInsightAttributeValue(10300,56) != null) {
def Approvers = getInsightAttributeValue(10300,50)
Approvers.each {
println "Item: $it"
}
}
It could be an arbitrary number of objects in the source field (10300). Do you have any idea how to proceed?
Thank you and best regards,
Nico