Query builder throwing error

dikshithara
Tera Contributor

Query builder throwing error even if the classes and the relationships are right.

I built a query builder in the following way:
Storage server -> Storage volume->Storage device->Host servers->Application. I added all the relatioships based on the cmdb_rel_ci table. 

Still query builder throwing the error:

Can someone please help me understand how to rectify this error.

7 REPLIES 7

Capture.PNG
This is how the query builder looks.

This seems to be out of my knowledge, for this I won't be able helping you 😞 let's hope somebody else will answer

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


AJ-TechTrek
Giga Sage
Giga Sage

Hi @dikshithara ,

 

As per my understanding why Query Builder might throw an error:


1. Relationship direction
Query Builder requires the relationships to be:
* Consistent in direction
(e.g., "Storage server hosts Storage volume" vs "Storage volume hosted on Storage server")
If the relationship is reversed in your environment or your diagram, it can break the chain.

 

2. Relationship type vs relationship name
Sometimes you might see the relationship in CMDB visually,
but Query Builder can't resolve it because:
* The relationship type isn't properly defined in the CMDB
* Or you picked the wrong type in Query Builder (e.g., picked "Depends on" instead of "Hosted on")

 

3. Classes not actually connected
Even if the classes are logically related, the actual relationship type may not exist or may use a parent/child class:
* e.g., Storage device may be linked to Computer rather than specifically to Host server
* Or Application is often linked to Business Application or Application Service instead of directly to Host server.

 

4. Relationship not published / active
Check in:
CMDB → Relationships → Relationship Types
Make sure:
* The relationship types between those classes are published (active = true).
* They use correct parent/child classes.


Solution to fix as per my understanding -


Step 1: Confirm relationships really exist
Go to:
CMDB → Relationships → Relationship Types
For each hop:
From To Relationship type
Storage server Storage volume e.g., Contains / Contained by
Storage volume Storage device e.g., Uses / Used by
Storage device Host servers e.g., Connected to / Connected from
Host servers Application e.g., Runs / Runs on
Make sure these relationship types:
* Are active
* Have the correct parent & child classes

 

Step 2: Use correct direction
In Query Builder, start from the left (root node) and add edges in correct direction.
E.g.,
Storage server → Storage volume
not Storage volume → Storage server.

 

Step 3: Check parent classes
Sometimes, the relationship is defined on a parent class:
* cmdb_ci_computer instead of Host servers
* cmdb_ci_storage_device instead of Storage device
In Query Builder:
* Use the parent class to see if it resolves.

 

Step 4: Use the relationship type in the relationship step
When you add the next node in Query Builder:
* Choose the relationship type from the drop-down that matches what's in CMDB.
* Don’t let it default to “Uses” if that's not what's in your environment.

 

Step 5: Validate in CMDB
Run this query in CMDB:
select * from cmdb_rel_ci
where parent.sys_class_name = 'your left node class'
and child.sys_class_name = 'your right node class'
* Make sure records actually exist.


Extra: Known workaround
If it still errors:
* Split the query into two smaller chains.
* Validate each.
* Combine later.


Quick checklist:
A. Check actual relationship type & direction


B. Confirm classes match exactly (or use parent class)


C. Confirm relationships are active & published


D. Confirm records really exist in cmdb_rel_ci


E. Avoid reversed or skipped hops

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
 

Thank You
AJ - TechTrek with AJ - ITOM Trainer
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
Topmate:- https://topmate.io/aj_techtrekwithaj (Connect for 1-1 Session)
ServiceNow Community MVP 2025