Record producer client script onSubmit

wakespirit
Kilo Guru

Dear all,

When we define a client script on record producer of type onSubmit

Q1  : Does this script is executer before record gets submit, at same time record gets submit, or after record gets submit and recorded ?

 

Q2 : I am calling my record producer by using a GlideModal APi, is there a way to close the GlideModal on this onSubmit script ? I have try GlildeWindow.get().destroy()  but it does not work

Any idea ?

regards

10 REPLIES 10

Hi,

I guess the below two lines will close the window no need to call the GlideWindow ,get().destroy()

var modal = new GlideModal('page');

modal.setBackdropStatic(true);

For more details refer the below link.

GlideModal closing

I thing the link you mention has nothing to do for closing the window, seems to be an old issue.

 because in my London version without this line of code mentionned in the link, if I click outside my window, the window is already modal so does not close

The way I am calling my window from my UI Action script is as below :

var gform=new GlideDialogWindow('test_producer');
	var user=g_form.getUniqueValue();
	var url="/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=c0810cf12fc3270061999bacf699b685&sysparm_user=" + user;
	alert(url);
	
	gform.setPreference('url_param',url);
	gform.setTitle('Test record producer');

	gform.render();

 

In my case I really want to close the window after it is submited, not setting it as modal as it is already modal

Hi,

Yes, you need to call GlideDialogWindow.get().destroy(); method to close the GlideDialogWindow.

You need to write client script to check whether all the fields are filled or not in the dialog window,if all the fields are filled then you  can call GlideDialogWindow.get().destroy(); method.

You can refer the below code, the below function will get executed after clicking on Submit/OK button 

function validateFields() {
   //Gets called if the 'OK' dialog button is clicked
   //Make sure dialog fields are not empty
   var fields = get("dial_fields").value;
   fields = trim(fields);
   if (fields == "") {
      //If fields are empty stop submission
      alert("Please provide fields to submit the dialog.");
      return false;
   }
   //If fields are not empty do this...
   GlideDialogWindow.get().destroy(); //Close the dialog window
   g_form.setValue("Fields", fields); //Set the 'Fields' field with field values in the dialog
}

For more details you can refer the below link.

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

 

Please mark it as correct/helpful if it helps for you.

Regards,

Pooja

In the sample link you mentionned, the GlideWindow.get().destroy() works because it is handle directly from the root HTML content of the UI page.

Please see below my UI page 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">
	
<g:evaluate var="jvar_url" expression="RP.getWindowProperties().get('url_param')">
</g:evaluate>
	
<button id="close" onclick="closeAck()" type="button">$[gs.getMessage("Close")]</button>
${jvar_url}
	<div>
	 
	<iframe id="rp_frame" src="${jvar_url}" width="800" height="600">
</iframe>
		
	</div>
<script>

addLoadEvent( function() {
onLoadFunction();

});


</script>	
</j:jelly>

As ou can see I have on top as part of the HTML content i have define an HTML button which call my UI page client method CloseAck() define as below

function closeAck() {
	alert("CLOSE ACK REACH");
	GlideDialogWindow.get().destroy();
	//saveProducer();
}

Doing this the dilog close correctly when pressing my CLOSE button in as HTML element.

BUT NOW CHECK MY HTML and you will see there is an Iframe where the src="${jvar_url}" contains the URL of my Record Producer to display in my Popup.

The Submit button is build inside that URL by the record producer.

My issue, is to close my dialog, from that submit button, and using destroy simply hangs my all formular and does not work because it is inside an Iframe.

any idea?

 

Hi,

Whether you solved your issue or not.If not, i suggest you to use GlideModal instead of GlideDialogWindow API as GlideModal is the replacement of GlideDialogWindow and by calling GlideDialogWindow.get().destroy() method closes the window before submitting form so,your page is hanging while submitting.

Try the below code it may help you.

var v=GlideModal.prototype.get('SCOPE.UI_PAGE_NAME');

v.destroy();

Refer below link it may help you.

https://community.servicenow.com/community?id=community_question&sys_id=34574369db1cdbc01dcaf3231f96...

Please mark it as correct/helpful if it helps for you.

Regards,

Pooja