How to add filter to the assignment group field in the modal pop-up?

Vasu20
Tera Contributor

I want the assignment group field in the modal to load only support groups where can i add the filter condition in the code here so that it shows only those.

function onClick(g_form) {

g_modal.showFields({
title: "Please provide all information for incident",
fields: [{
type: 'textarea',
name: 'u_incidentreason',
label: 'Incident description:',
mandatory: true
}, {

type: 'reference', // type of modal (ie text, reference, etc)
name: 'assignment_group', // reference field on the current record used to search
label: 'Assignment Group', // message to display above the search field
mandatory: true, // sets the field to mandatory
reference: 'sys_user_group', // table that the reference field in "name" refers to
referringTable: 'incident', // table of the current record
referringRecordId: g_form.getUniqueValue() // sys_id of the current record

}],
size: 'md'

}).then(function(fieldValues) {

g_form. setValue('u_incidentreason', fieldValues.updatedFields[0].value); 
g_form.setValue("u_incident_creation", 'true'); 
g_form.save();

}

1 ACCEPTED SOLUTION

Glad to help.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Hi,

I doubt this can be achieved.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Will update the same.Thank you so much for all the help.

 

Best Regards,

Vasu

Glad to help.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Dragos
Tera Contributor

Hi Vasu,

 

I ran into the same issue and made use of g_modal.showFrame which calls an UI Page configured by you with a small field, like in your case, assignment group and pulls out the sys_user_group with simple query attribute. 

You will of course, need to remove this part of your code:


{

            type: 'reference', // type of modal (ie text, reference, etc)
            name: 'assignment_group', // reference field on the current record used to search
            label: 'Assignment Group', // message to display above the search field
            mandatory: true, // sets the field to mandatory
            reference: 'sys_user_group', // table that the reference field in "name" refers to
            referringTable: 'incident', // table of the current record
            referringRecordId: g_form.getUniqueValue(), // sys_id of the current record
            sysparm_query: 'sysId1,sysId2'

        }

and add the following at the end. 

g_modal.showFrame({
     url:'/{name of ui page}?from_workspace=true&{any parameter that will help you achieve your filter}',
     title: 'string',
     size: 'sm, md or lg',
     height: in px,
     callback: function (ret,data) {
     if (ret)
          updateData(data);
     }
});			
function updateData(data){
	if(data.group !== ""){
	       g_form.setValue('assignment_group',data.group);
	       g_form.save();
         }
}

 

Here's also an example of an UI Page:

HTML:

<g:ui_form>
			
		<input type="hidden" id="support_lvl" name="support_lvl" value="${jvar_support_lvl}" />

		Assignment Group  <g:ui_reference name="group" id="group" table="sys_user_group" completer="AJAXTableCompleter" query="${jvar_query}" />
	
		<table width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td align="left" nowrap="true"><br />
				<g:dialog_buttons_ok_cancel ok="return ok()" cancel="return cancel()" ok_type="button" ok_style_class="btn btn-primary" cancel_type="button"/>
			</td>
		</tr>
		</table>

</g:ui_form>


Client: 

function cancel() {
    window.location.href = window.location.href;
}

function ok() {

    var x = document.getElementById("group").value;
    iframeMsgHelper.confirm({
        group: x
    });
    if (x == "") {
        if(confirm('Please provide data to submit the dialog.')){
			alert('You will need to restart the process');
		}
		
    }

}
var iframeMsgHelper = (function() {
    function createPayload(action, modalId, data) {
        return {
            messageType: 'IFRAME_MODAL_MESSAGE_TYPE',
            modalAction: action,
            modalId: modalId,
            data: (data ? data : {})
        };
    }

    function pm(window, payload) {
        if (window.parent === window) {
            console.warn('Parent is missing. Is this called inside an iFrame?');
            return;
        }
        window.parent.postMessage(payload, location.origin);
    }

    function IFrameMessagingHelper(window) {
        this.window = window;
        this.src = location.href;
        this.messageHandler = this.messageHandler.bind(this);
        this.window.addEventListener('message', this.messageHandler);
    }

    IFrameMessagingHelper.prototype.messageHandler = function(e) {
        if (e.data.messageType !== 'IFRAME_MODAL_MESSAGE_TYPE' || e.data.modalAction !== 'IFRAME_MODAL_ACTION_INIT') {
            return;
        }
        this.modalId = e.data.modalId;
    };

    IFrameMessagingHelper.prototype.confirm = function(data) {

        var payload = createPayload('IFRAME_MODAL_ACTION_CONFIRMED', this.modalId, data);
        pm(this.window, payload);
    };

    return new IFrameMessagingHelper(window);
}());

@Dragos 

Can you share your relevant scripts so that it helps future members as well?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader