
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I’ve created a workflow using an Order Guide and am currently having trouble configuring a filter for the ‘Requested for’ field. I’d really appreciate any insights or suggestions.
Page1:
The user selects the order type, with the available options configured in the Order Guide.
Page 2:
- The top half of the page contains variables loaded from the Catalog Item.
- The bottom half contains variables from a Variable Set.
- The ‘Requested_for’ field is a variable from the Variable Set.
Goal:
I want to dynamically control the options shown in the ‘Requested for’ field based on the selection from another field — a Multiple Choice variable named ‘option’, which allows the user to select either ‘Send and Receive’ or ‘Receive only’.
- If ‘Send and Receive’ is selected: Only display users where ‘employee_number’ field is not empty.
- If ‘Receive only’ is selected: No filter should be applied – display all users.
Current Status:
I have a Catalog Client Script and a Script Include to try to apply this logic, but the filter is not working — all user records are being displayed regardless of the selection.
I understand that both ‘onChange’ and ‘onLoad’ scripts are required, but I’m currently testing with just the onChange script.
If anyone has encountered a similar situation or has any suggestions, I’d really appreciate your input. Thank you!
Catalog client script
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue === '') return;
// Get selected value from catalog item variable 'options' var selectedValue = g_form.getValue('options') || '';
// Fully qualified name for 'requested_for' inside variable set var requestedForVar = 'efax_catalog_item_variable_set.requested_for';
// Clear previous value before applying a new filter g_form.setValue(requestedForVar, '');
var ga = new GlideAjax('RequestedForFilter'); ga.addParam('sysparm_name', 'getFilter'); ga.addParam('sysparm_selected_option', selectedValue);
ga.getXMLAnswer(function(answer) { if (!answer) { g_form.showFieldMsg(requestedForVar, 'No filter returned. Please contact support.', 'error'); return; }
try { // Apply the dynamic reference qualifier to 'requested_for' g_form.setReferenceQual(requestedForVar, answer); g_form.refreshReference(requestedForVar); g_form.showFieldMsg(requestedForVar, 'Filter applied: ' + answer, 'info'); } catch (e) { g_form.showFieldMsg(requestedForVar, 'Error applying filter: ' + e.message, 'error'); } }); } |
Script Include
var RequestedForFilter = Class.create(); RequestedForFilter.prototype = Object.extendsObject(AbstractAjaxProcessor, { getFilter: function() { var selectedValue = this.getParameter('sysparm_selected_option') || ''; gs.info('[RequestedForFilter] PARAM = ' + selectedValue);
if (selectedValue === 'send_and_receive') { this.getResponse().setAnswer('employee_numberISNOTEMPTY'); } else { this.getResponse().setAnswer('active=true'); } } }); |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
client script won't help in filtering users.
you need to use advanced reference qualifier on that variable, something like this
Note: Community converts colon : to : so please use : correctly
javascript: var query = ''; if(current.variables.options.toString() == 'send_and_receive') query = 'employee_numberISNOTEMPTY'; 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
a month ago
Hi Mari,
In place of the scripts, you can simply use a reference qualifier on the requested_for variable.
javascript: var ret='active=true'; if(current.variables.options === 'send_and_receive'){ret='employee_numberISNOTEMPTY';}ret;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @Brad Bowman ,
Thank you so much for your comment. It did not filter out the users whose employee number is empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
client script won't help in filtering users.
you need to use advanced reference qualifier on that variable, something like this
Note: Community converts colon : to : so please use : correctly
javascript: var query = ''; if(current.variables.options.toString() == 'send_and_receive') query = 'employee_numberISNOTEMPTY'; 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
a month ago
Hello @Ankur Bawiskar,
Thank you for your suggestion. It worked like a charm! I really appreciate your help.