- 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 01:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 01:16 AM
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);
In reference qualifier.
Here else part is not working can you help me what is wrong here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 01:25 AM
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: '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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 01:32 AM
it's not working it showing all categories even I select application. can you help me with if and else conditions
- 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