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

Yes thank you what is the difference between "!current.variables.application" and this current.variables.application != "" ? 

Why for me !current.variables.application this worked

when you use this !current.variables.application it means the value is not empty or not null

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

From a syntax perspective, I was expecting the last part to be "return query" rather than just "query".   But I'm still a novice in javascript.

TejasriK
Tera Contributor

javascript&colon; 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 : 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id);

syntax for if else condition is - condition ? executes if true : executes if false
specify the condition and if it is true then the line before colon will executes if the condition is false the line after the colon will executes.

TejasriK
Tera Contributor
javascript&colon; 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 : 'u_type=category^u_inactive=false^u_catalog_item='+(current.cat_item.sys_id||current.request_item.cat_item.sys_id);



syntax for if else condition is - condition ? executes if true : executes if false
specify the condition and if it is true then the line before colon will executes if the condition is false the line after the colon will executes.