GlideModal - Opening a record in a glide modal and Update and Save events

Vegard S
Kilo Sage

I'm using the GlideModal to display a record in a modal. The reason I'm using GlideModal and not GlideModalForm is because GlideModalForm doesn't have proper auto height settings. While GlideModal has an autoHeight method
I am not using a UI Page, just displaying the record using renderIframe.

 

I can't find much info on this in the documentation, but I've noticed that first of all, I need to tap into the g_form via the iFrame. Fair enough, I had to do that using GlideModalForm too, but I have (as far as I can tell) no events for when the form is being submitted. So I can refresh the whole page. 

 

My code looks like this at the moment:

 

function showCloseNotesForm(){
	//Get the table name and sys_id of the record
	var tableName = g_form.getTableName();
	var sysID = g_form.getUniqueValue();
	var view_name = 'close_modal';
	var view_forced = 'true';
	var title = 'Sak utenfor SN';

	var d = new GlideModal();
	d.setTitle(title);
	d.setWidth(1200);
	d.setAutoFullHeight(true);

	// Reload the form when modal is closed
	d.on("beforeclose", function (){ location.reload(); });

	var url = tableName + '.do?sys_id=' + sysID + '&sysparm_view=' + view_name + '&sysparm_form_only=true&sysparm_clear_stack=true&sysparm_view_forced=' + view_forced;

	d.renderIframe(url, function (){	
		var iframe = d.$window.find("iframe")[0];
		var iframeWindow = iframe.contentWindow ? iframe.contentWindow : iframe.contentDocument.defaultView;
		var d_form = iframeWindow.g_form;

		// Remove uncessary elements
		iframeWindow.$j(".form_action_button_container").remove();
		iframeWindow.$j(".related-links-wrapper").remove();

		// Set values to the form
		d_form.setValue('state', '3');
		d_form.setValue('resolution_code', 'Sak sendt ut av ServiceNow');
		
		// Reload the entire form when submit buttons are clicked
		iframeWindow.$j('button[type="submit"]').click(function() {
			setTimeout(function(){
				location.reload();
			}, 1000); // Wait for 1 second before refreshing the page
			
		});
	});
}

 

The only way I can refresh the page is to essentially query all buttons with type submit, and add a Click handler. 

Then, to prevent the codefrom running too quickly (before the server has managed to to update) I currently use a setTimeout function for around 1 second. 

 

This seems not ideal at all. 

0 REPLIES 0