filter g_modal based on field form value

anas_m
Tera Contributor

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

4 REPLIES 4

James Chun
Kilo Patron

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 

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

 

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:

 

Bit frustrating as it seems like an easy configuration but hope someone has a better solution!

 

Cheers

 

Hi @James Chun 

 

Thank you for the feedback,  I'll keep searching and then update the question if I find a solution