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

else part not working.

If no application  category is not populating

@rahul16 

are you having any category records satisfying the query in else

then only it will work

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

yes we have but still not showing values 

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); else 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; query; 

working fine

@rahul16 

it's similar to what I suggested above you just swapped the query based on if condition

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