How to create a popup dialog box on a UI Action and populate a field

mkader
Kilo Guru

Hello,

I have a "Reject" UI Action that I need to display a pop-up for with a comment box. They need to write the reason for the rejection. After they click ok, the rejected comment populates a reason field on the form. 

How can I set this up.

I am struggling to follow the example provided by SN Guru:

https://www.servicenowguru.com/system-ui/glidedialogwindow-advanced-popups-ui-pages/

Thanks!

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

You can pretty much duplicate the Cancel Change UI Action form the change_request table.

var rejectconfirmDialog;

function loadConfirmDialog() {
	var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
	rejectconfirmDialog = new dialogClass("change_confirm_cancel", false, 648, 250);
	rejectconfirmDialog.setTitle(new GwtMessage().getMessage("Reject Task")); //Modify title to display on popup
	rejectconfirmDialog.render();
}

function moveToCancel(notes) {
//g_form.setValue("state",1) Possible to set the state here.
		g_form.setValue("work_notes", notes); //Pass reason worknotes to a field
		rejectconfirmDialog.destroy();
		gsftSubmit(null, g_form.getFormElement(), "UI action name"); // Call UI action to run server script
	
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

 

View solution in original post

20 REPLIES 20

Kieran Anson
Kilo Patron

Hi,

You can pretty much duplicate the Cancel Change UI Action form the change_request table.

var rejectconfirmDialog;

function loadConfirmDialog() {
	var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
	rejectconfirmDialog = new dialogClass("change_confirm_cancel", false, 648, 250);
	rejectconfirmDialog.setTitle(new GwtMessage().getMessage("Reject Task")); //Modify title to display on popup
	rejectconfirmDialog.render();
}

function moveToCancel(notes) {
//g_form.setValue("state",1) Possible to set the state here.
		g_form.setValue("work_notes", notes); //Pass reason worknotes to a field
		rejectconfirmDialog.destroy();
		gsftSubmit(null, g_form.getFormElement(), "UI action name"); // Call UI action to run server script
	
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}

 

Hey @Kieran Anson - Thanks for your response. I am trying to follow the logic behind this. I see there is a script include and a glideajax. I haven't used glideajax before. How can I access what the ajax is doing?

Hi,

The glideAjax in the Change Request UI Action is checking what value to set the state to when someone is wanting to cancel a change.

You likely don't need this so as per the script I added, you can just set the state value

//g_form.setValue("state",1) Possible to set the state here.

@Kieran Anson - this works, but trying to set on another field outside of work notes. Can you explain the following line:

g_form.setValue("work_notes", notes); //Pass reason worknotes to a field

Where is notes coming from? If I want to do this on the short description would I just remove notes and do it like this:

g_form.setValue("short_description"); //Pass reason worknotes to a field

Hi sure,

The UI page that loads that allows the user to enter a value calls the moveToCancel function and passes the value entered in the reasons box as the variable value 'notes'

You can use this value anywhere, if you wanted to set the reason as the short description then yes you can do 

g_form.setValue("short_description", notes ); //Pass reason worknotes to a field