How to close modal window when record producer is submitted

victor21
Tera Guru

Hi Listers,

We are currently displaying a record producer in a modal window using ui page

<?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>

	<iframe id="rp_frame" src="${jvar_url}" width="800" height="600" />

</j:jelly>

The problem is that when the producer Submit button is clicked, the new created record is displayed inside the dialog window. Is there a simple way to just close the modal window after the producer is submitted?.

Thanks for your help.

Victor

1 ACCEPTED SOLUTION

victor21
Tera Guru

After some investigation I finally found a solution which is not altogether perfect - but serves my purpose. The idea is to use .load() event of the iframe

var iframe = $j('#rp_frame');
iframe.load(function(){
	var catItem = iframe.contents().find('#cat_item_view');
	var catItemId = catItem.attr('id');
	if(!catItemId){
        GlideDialogWindow.get().destroy();
    }
}

Regards,

 

Victor.

 

View solution in original post

9 REPLIES 9

Sorry victor, I don't know what you have or have not tried or thought of so I just wanted to suggest what works for me and most everyone else when using UI Page.

You'd need to handle the validation then.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

victor21
Tera Guru

After some investigation I finally found a solution which is not altogether perfect - but serves my purpose. The idea is to use .load() event of the iframe

var iframe = $j('#rp_frame');
iframe.load(function(){
	var catItem = iframe.contents().find('#cat_item_view');
	var catItemId = catItem.attr('id');
	if(!catItemId){
        GlideDialogWindow.get().destroy();
    }
}

Regards,

 

Victor.

 

Yep and using 

GlideDialogWindow.get().destroy();

Glad you got it resolved. Using iframes is already a wonky process as is...so when you validate appropriately...you can close it properly.

Take care!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

This helped me so much after being stuck for ages on a similar requirement!

 

For anyone else reading this, here is my HTML from my UI Page. My requirement is to load/embed a custom service portal widget within my UI Page/iframe (this is done in the ui page client script) and then wait for a $scope.$emit event from the client script of the widget to do something. The event was simply emitted after a button click on the widget. I was having no luck figuring out how to listen for an event from my UI Page and iframe.load was the only thing that worked. 

 

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <iframe id="portal_page_frame" style="height: 700px; width: 100%; border: none;"></iframe>
    <script>
        (function() {
            var iframe = $j('#portal_page_frame');
            iframe.load(function(){
				//listen for the success event from the embedded widget
                var iframeScope = iframe[0].contentWindow.angular.element(iframe[0].contentDocument).scope();
                iframeScope.$on('signatureSubmittedSuccess', function () {
                    setTimeout(function() {
                        GlideDialogWindow.get().destroy();
                    }, 1750);
                });
            });
        })();
    </script>
</j:jelly>

 

 

 

Ct111
Tera Sage

Hello,

I think the below case is similar to yours . Please , have a look at it and implement in yours scenario

https://community.servicenow.com/community?id=community_question&sys_id=3b1eb843dbf42f08d58ea345ca96...

 

Mark my ANSWER as CORRECT and HELPFUL if it helps...