- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 12:17 AM - edited 11-18-2022 01:05 AM
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: '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: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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 01:36 AM
use this
javascript: 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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:22 AM
Yes thank you what is the difference between "!current.variables.application" and this current.variables.application != "" ?
Why for me !current.variables.application this worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 03:38 AM
when you use this !current.variables.application it means the value is not empty or not null
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 10:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 06:05 AM
javascript: 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 06:10 AM
javascript: 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.