Automating lookup of object Inbound References
Asked by Ari Raatikainen:

Hi,  
Using automation, how to lookup from a object its all inbound references? See picture where object is having 3 references to "Application" objects and which are stored in different schema. The outbound attribute in referenced Application object is "Business application".

![Screenshot.png](/t5/image/serverpage/image-id/336086i9B625FC0BC8CDF67/image-dimensions/391x170?v=v2 "Screenshot.png")  

How the output could be used e.g. in mail body?


Answers:
author: Kevin Patterson
body: Hi [@Ari Raatikainen](/t5/user/viewprofilepage/user-id/5489268)

You should be able to do this with an inbound reference in your lookup Objects AQL query.

In your lookup Objections Action set your Schema to the Schema that contains your application objects and for your query start with:

```
object HAVING inR(Key in ({{issue.customfield_XXXXX}}))
```

Be sure an replace customfield_XXXXX with your custom field ID that contains the object that has the relationships you are trying to retrieve.

Once you have validated that this is returning your objects (I use a log action to do this) you can build on this AQL and adjust it to return only the results based on further filtering ie: only certain object types and/or relationship/link names.

Here is a link to Atlassian documentation that I use when building my AQL queries <https://support.atlassian.com/jira-service-management-cloud/docs/use-assets-query-language-aql/>

Let us know how you it works out.

comments: author: Ari Raatikainen
body: Hi thanks for ideas. After quite a many different experiments I still cannot figure out how to achieve the desired output. Namely I struggle how to build the automation that loops the results of first Lookup query.  

Lets use below example to further describe what I would like to achieve:

With Jira automation (lookupObjects) I get the following output as result of AQL query from Jira assets schema: ***Assets*** and object: ***Laptops***:

```
ObjectType = "Laptops" AND "Status" IN ("Active") AND "Manufacturer" IN ("Apple")
```

-\> resulting  

IEA-490;LAP-01-APP-2939; IEA-180; FJE-2902-CJIF;  
IEA-494;LAP-03-APP-6794; IEA-181; FJEI-9284-FIOC;  
IEA-497;LAP-08-APP-8889; IEA-181; FJ-E0283-FJO24;  
IEA-498;LAP-09-APP-2813; IEA-181; FJ-3929-CJID028;  
IEA-499;LAP-121-APP-0012; IEA-180; FE-3083-FJIOE;  
IEA-504;LAP-18-APP-3811; IEA-181; FE-294F-39JFO;

above attributes are: Jira object key; Name; Model; Serial Number;

What I don't figure out how to correctly build components / loop that would use above as input, and using Jira object key values to find laptop owner name which is an outbound reference for Laptops object. The Owner name is stored in Schema: **People** in object **Person** , and attribute**Name**

As final results I would like to have an Output (email body) like this

Jira object key; Name; Model; Serial Number; Owner  
IEA-490;LAP-01-APP-2939; IEA-180; FJE-2902-CJIF; Alana Grant  
IEA-494;LAP-03-APP-6794; IEA-181; FJEI-9284-FIOC; Jimmy Showman  
IEA-497;LAP-08-APP-8889; IEA-181; FJ-E0283-FJO24; Peter Noname  
IEA-498;LAP-09-APP-2813; IEA-181; FJ-3929-CJID028; Anna Best  
IEA-499;LAP-121-APP-0012; IEA-180; FE-3083-FJIOE; Joe Foolie  
IEA-504;LAP-18-APP-3811; IEA-181; FE-294F-39JFO; Alana Grant

I look forward to see a visual snip of Jira automation explained for resolving this? Thanks in advance.


author: Ari Raatikainen
body: Hi thanks for ideas. After quite a many different experiments I still cannot figure out how to achieve the desired output. Namely I struggle how to build the automation that loops the results of first Lookup query.  

Lets use below example to further describe what I would like to achieve:

With Jira automation (lookupObjects) I get the following output as result of AQL query from Jira assets schema: ***Assets*** and object: ***Laptops***:

*ObjectType = "Laptops" AND "Status" IN ("Active") AND "Manufacturer" IN ("Apple")*

--\> resulting  

IEA-490;LAP-01-APP-2939; IEA-180; FJE-2902-CJIF;  
IEA-494;LAP-03-APP-6794; IEA-181; FJEI-9284-FIOC;  
IEA-497;LAP-08-APP-8889; IEA-181; FJ-E0283-FJO24;  
IEA-498;LAP-09-APP-2813; IEA-181; FJ-3929-CJID028;  
IEA-499;LAP-121-APP-0012; IEA-180; FE-3083-FJIOE;  
IEA-504;LAP-18-APP-3811; IEA-181; FE-294F-39JFO;

above attributes are: Jira object key; Name; Model; Serial Number;

What I don't figure out how to correctly build components / loop that would use above as input, and using Jira object key values to find laptop owner name which is an outbound reference for Laptops object. The Owner name is stored in Schema: **People** in object **Person** , and attribute**Name**

As final results I would like to have an Output (email body) like this

Jira object key; Name; Model; Serial Number; Owner  
IEA-490;LAP-01-APP-2939; IEA-180; FJE-2902-CJIF; Alana Grant  
IEA-494;LAP-03-APP-6794; IEA-181; FJEI-9284-FIOC; Jimmy Showman  
IEA-497;LAP-08-APP-8889; IEA-181; FJ-E0283-FJO24; Peter Noname  
IEA-498;LAP-09-APP-2813; IEA-181; FJ-3929-CJID028; Anna Best  
IEA-499;LAP-121-APP-0012; IEA-180; FE-3083-FJIOE; Joe Foolie  
IEA-504;LAP-18-APP-3811; IEA-181; FE-294F-39JFO; Alana Grant

I look forward to see a visual snip of Jira automation explained for resolving this? Thanks in advance.


Tags: assets

cloud

jira-service-management-cloud