UI Action with pop up SOW

Community Alums
Not applicable

Hi,

Is there any way in the reference to also pass a query? for example that the user will only can select user that are active?

unction onClick(g_form) {

    var fields = [
        {
            type: 'choice',
            name: 'reason_code',
            label: getMessage('Reason code'),
            value: getMessage(' -- Select -- '),
            choices: [{
                displayValue: 'Duplicate',
                value: 'duplicate'
            },
                {
                    displayValue: 'Canceled',
                    value: 'canceled'
                }
            ],
            mandatory: true
        },
        {
            type: 'reference',
            name: 'caller_id',
            label: getMessage('What is your name?'),
            mandatory: true,
            reference: 'sys_user',
            referringTable: 'incident',
            referringRecordId: g_form.getUniqueValue(),
			value: g_form.getValue('caller_id'),
			displayValue: g_form.getDisplayValue('caller_id')
        }
    ];

    g_modal.showFields({
        title: "Enter your reason",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
        g_form.setValue('work_notes', fieldValues.updatedFields[0].value);
        g_form.setValue('caller_id', fieldValues.updatedFields[1].value);
        g_form.save();
    });
}

 

1 REPLY 1

Siddhesh Jadhav
Kilo Sage
Kilo Sage

Hi @Community Alums — a few things to note about your code, and a working alternative

A couple of problems to be aware of:

  1. g_modal.showFields() is convenient, but it doesn’t reliably support passing a reference qualifier the same way a regular form reference does. That means you can’t consistently enforce active=true from inside showFields().

  2. Browser / platform differences
    g_modal or g_modal.showFields() may not be available in older/unsupported UI variants. For a stable, filterable reference inside a modal, prefer GlideDialogWindow + a Jelly UI Macro / UI Page.

 

Recommended approach (stable + filterable): GlideDialogWindow + UI Macro

Why: you can use <g:ui_reference ... query="active=true" /> inside the dialog and reliably show only active users.

1) UI Action client script — opens the modal:

function openReasonModal() {
    var dialog = new GlideDialogWindow('glide_modal_reason_dialog');
    dialog.setTitle('Enter your reason');
    dialog.setSize(600, 300);
    dialog.setPreference('current_caller', g_form.getValue('caller_id'));
    dialog.render();
}

Make sure the UI Action config has:

  • Client = true

  • Onclick = openReasonModal()

2) Create a UI Macro named glide_modal_reason_dialog with this Jelly script:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<script>
		function saveReason() {
            var reason = gel('reason_code').value;
            var caller = gel('caller_id_ref').value;

            // Pass back to the opener
            GlideDialogWindow.get().destroy();

            // Update fields on the form
            g_form.setValue('work_notes', reason);
            g_form.setValue('caller_id', caller);
            g_form.save();
        }
	</script>

	<div style="padding: 20px;">

		<label>Reason Code</label>
		<select id="reason_code" class="form-control">
			<option value="duplicate">Duplicate</option>
			<option value="canceled">Canceled</option>
		</select>

		<br />

		<label>What is your name?</label>
		<g:ui_reference name="caller_id_ref" table="sys_user" value="${current_caller}" query="active=true"
			mandatory="true" />

		<br /><br />

		<button type="button" class="btn btn-primary" onclick="saveReason()">Submit</button>
		<button type="button" class="btn btn-default" onclick="GlideDialogWindow.get().destroy()">Cancel</button>
	</div>
</j:jelly>
  • Your original approach with g_modal.showFields() is easy but not ideal when you need a reliable reference qualifier.

  • The GlideDialogWindow + UI Macro approach is robust, lets you put query="active=true" on the reference control, and reliably returns values to the parent form.

 

Thanks, and regards,
Siddhesh Jadhav

 

If my solution helped to resolve your query, please mark it as Accepted and Helpful