How to create advance reference qualifier with if and else conditions

rahul16
Giga Guru

I am using a variable set and I am filtering conditions like

Application<category<sub-category

if there is no application then category<sub-category

 

javascript&colon; 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application;

 

This will work only if user select application

 

How can I use it if the application is empty set the application as empty?

if(current.variables.application){
return current.variables.application;
}else{
return '';
}

 

I created like this 

javascript&colon;if (current.variables.application != "") 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application;else 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id);

 

but else part not working

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@rahul16 

use this

javascript&colon; var query; if (current.variables.application != "") query = 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application; else query = 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id); query;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

19 REPLIES 19

In your if condition, the system can't find out current object, so it will not execute.

You can pass two parameters one sys id of your cat item or ritm(param1) and the other one the application(param2).

From Script include, you need to glide to the table where you are fetching the category,subcategory and use addQuery methods for each part of your above query and use the param1 to get the current cat item/ritm details.

Once your query is done, you can then return the result sys id (or ids) back to the reference qualifier.

javascript&colon;if (current.variables.application != "") 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application;else 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id);

 

In reference qualifier.

Here else part is not working can you help me what is wrong here

If you don't want to use Script include, can you try once with OR condition? Every time there is an application, your first criteria will be fulfilled, otherwise it will move to OR condition.

Something like this:
javascript&colon; 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application+'^OR u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id);

Please test with and without application. You may need to move the placement of OR condition.

it's not working it showing all categories even I select application. can you help me with if and else conditions

Ankur Bawiskar
Tera Patron
Tera Patron

@rahul16 

use this

javascript&colon; var query; if (current.variables.application != "") query = 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id)+'^u_application='+current.variables.application; else query = 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id); query;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader