filter g_modal based on field form value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 10:11 AM
Hi ServiceNow Community,
I want to filter a g_modal reference field based on opened_for field value which is present in the form. Could you please tell me how can I make it possible ?
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 12:16 PM - edited 03-17-2024 12:16 PM
Hi @anas_m,
You can pass values to the UI Page within the client script like below:
function openModal() {
var gm = new GlideModal('test');
gm.setTitle('My Modal');
gm.setPreference( 'sysparm_assigned_to', g_form.getValue('assigned_to')); //change with your field value
gm.render();
}
Then, within the UI Page, you can use the value via:
<j:set var="jvar_user_id" value="${RP.getWindowProperties().get('sysparm_assigned_to')}"/>
<g:ui_reference name="QUERY:sys_id=${jvar_user_id}" table="sys_user" />
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:45 AM
Hi @James Chun ,
Thanks a lot for your response. Could you please tell me how can I pass it to my UI Action script ?
Here's my script :
function onClick(g_form) {
g_modal.showFields({
title: getMessage("Linked to"),
fields: [{
type: 'reference',
name: 'u_associated',
label: getMessage('test'),
reference: 'task',
referringTable: 'interaction',
referringRecordId: g_form.getUniqueValue(),
value: '',
displayValue: ''
}],
size: 'lg'
}).then(function(fieldValues) {
g_form.setMandatory('work_notes', true);
g_form.save();
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 12:54 PM - edited 03-18-2024 01:34 PM
Hi @anas_m,
Apologies, you were talking about g_modal, not the GlideModal.
Unfortunately, I couldn't find anything to apply a reference qualifier with the g_modal API.
But did find 2 workarounds:
- Apply the reference qualifier on the Dictionary level. i.e. on your 'u_associated' field. But not that this will be applied to other places such as in the form view
- Although I haven't verified it, someone shared a workaround using an UI Page - https://www.servicenow.com/community/hrsd-forum/how-to-add-filter-to-the-assignment-group-field-in-t...
Bit frustrating as it seems like an easy configuration but hope someone has a better solution!
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 05:38 AM
Hi @James Chun
Thank you for the feedback, I'll keep searching and then update the question if I find a solution