related list not filtering

El Cuchi
Tera Guru

Hi All,

 

I hope everything is ok at your end.

Situation

I created a related list between "business application" and "Catalog Tasks" (dont want to use the OOB one).

Relationship details:

Applies to table = cmdb_ci_business_app

Queries from: sc_task

Query:  "current.addQuery('cmdb_ci', parent.sys_id);

 

this works fine. However, i would like to add one more filter and i dont know how to do it.

I would like to also filter where the catalog task is for a specific "item" (service catalog item)/

 

how do i do that?

 

regards

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @El Cuchi 

 

Try this way

 

var orQuery = glideRecord.addQuery('risk', 1);
orQuery.addOrCondition('risk', 2);

 

https://www.servicenow.com/community/itsm-forum/finding-union-of-two-queries-query-business-rule/m-p...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

KrishnaKamal
Tera Contributor

Hey! Try this. 

You can add multiple filters using 'addQuery' or 'addOrCondition'

var getTasks  = current.addQuery('cmdb_ci', parent.sys_id);
getTasks.addQuery('request_item.cat_item', 'SYSID_OF_YOUR_ITEM'); //catalog item name is on the request_item table

//if you want to use OR condition
var getTasks  = current.addQuery('cmdb_ci', parent.sys_id);
getTasks.addOrCondition('request_item.cat_item', 'SYSID_OF_YOUR_ITEM'); 
 

current.addQuery (assuming current is an instance of GlideRecord) returns an object of "type" GlideQueryCondition.

So variable getTasks is an instance of GlideQueryCondition.

But instances of GlideQueryCondition have no addQuery method.

Instances of GlideQueryCondition have only two methods: addCondition and addOrCondition (as @Dr Atul G- LNG too suggested).

But no addQuery.

Thus your suggestion:

 

getTasks.addQuery('request_item.cat_item', 'SYSID_OF_YOUR_ITEM');

 

will not work.

-O-
Kilo Patron
Kilo Patron

You can call current's addQuery method multiple time:

current.addQuery('cmdb_ci', parent.sys_id);
current.addQuery('request_item.cat_item', '<sys_id of the desired Catalog Item>');