Return Information from Insight Object based on custom field value

Andrew Downs August 16, 2018

Hi guys,

I need some assistance please, I have a requirement to do a Joiner, Mover, Leaver (JML) process, I have received some assistance on the forum but am at a point again where I seem to be having issues.

 The process would be as follows:

 

1) A user logs the JML on the Jira Portal

2) Risk an compliance officer will open the SSD in Jira and transition the call through the necessary steps

 

I have the validation and account creation steps working, but what I need to do is obtain the site address information from the insight object.

 

Currently my code looks as follows:

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.json.JSONObject
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor

// Enable Logging
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.info "Info Statements"

// Define Required Component Access

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

// Get Issue ID that contains the Data
//def issueKey = issue.getKey()
//MutableIssue issue = issueManager.getIssueObject(issueKey)
Issue issue = issueManager.getIssueObject( "SSD-18229" );


// Get field values
def userActiveDirectoryID = customFieldManager.getCustomFieldObjectByName("User Active Directory ID");
def userActiveDirectoryIDValue = issue.getCustomFieldValue(userActiveDirectoryID);
def internetGroupID = customFieldManager.getCustomFieldObjectByName("Internet Group ID");
def internetGroupIDValue = issue.getCustomFieldValue(internetGroupID);
def siteID = customFieldManager.getCustomFieldObjectByName("Site Code");
def siteIDValue = issue.getCustomFieldValue(siteID).name.toString().replaceAll('\\[','').replaceAll('\\]','').trim();
def iqlSearch = "Name=" + siteIDValue

/* 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);

def objects = iqlFacade.findObjectsByIQLAndSchema(6, "objectType=Site and Name=${siteIDValue}" ); // 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.info("Insight object: " + objects[0]);

 I am able to get a result into objects[0] but all it returns is the following:

[S7144 (SAM-9025)]

What I need from this is the following fields:

Reporting Name

Street Address

Suburb

City

Province

Country

 

Each of these fields do exist on the Asset created within Riada Insights.

 

Is what I am trying to do the correct way to retrieve this information?

 

I did have a look at https://documentation.riada.se/display/ICV54/Objects+-+REST, specifially the /rest/insight/1.0/object/navlist/iql section, but cannot seem to get that post to work either in order to return just the one object.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events