Open a modal after form submission

jonndoe
Kilo Contributor

Hi guys,

I was wondering if I could open a modal popup with some data in it after a record producer is submitted in Service Portal. I have this record producer that requires displaying some information to the users upon submitting a form and wonder if someone could shed some light on how to achieve this please?

Many thanks,

JD

1 ACCEPTED SOLUTION

here is an example onload client script I wrote that should work for either SP or OOB views. you can render direct content in the glidemodal like this code below. If you would rather use a ui page that is fine for the GM, but for the spModal, you would need to create a new SP widget to display it. this should give you the concept though. spModal is only available on Portal, so that is why we handle both cases in one script. Make sure you select UI Type = All in your client script.



function onLoad() {


    //Type appropriate comment here, and begin script below


  if (typeof spModal != 'undefined') {


      spModal.open({


          message: 'This is a test SP modal',


          title: 'Test SP Modal'


      });


  } else {


      var gm = new GlideModal();


      gm.setTitle('Test GM');


      gm.renderWithContent('This is a test GlideModal');


  }


}



This technically should work the same in a catalog onSubmit client script, but I still feel there will be an issue with redirects in the OOB view, though it actually may work fine in the SP because it is a single page app so doesn't do a true redirect after submission.


View solution in original post

29 REPLIES 29

Not a problem, please find below. I have included this as a catalog client script and have made UI type to both.



function onSubmit() {


  var tc_value = g_form.getValue('u_tandc_agree');


  if (tc_value == 'false') {  


    console.log('You need to agree to the terms & conditions before submitting');


    return false;  


  }



else{


        var gdw = new GlideDialogWindow('u_software_licence_key');


        gdw.setTitle('My Modal');


        gdw.setSize(650,3000);


        gdw.render();


        }


}




Thanks again for your help!


Just to be sure, u_software_licence_key is the name of your UI Page?


-Anurag

That's correct Anurag.


jbarnesciti is a maverick in this area, any ideas Jon?


-Anurag

thx Anurag     .



the primary issue here, from what I can tell, is that when you hit submit, once that onsubmit function finishes, your page is going to submit and redirect.



so showing the modal from the onsubmit function prob won't work.



since record producers will redirect you to the record itself, I would suggest that you show the modal window in an onload client script for the target table. And only show the popup if g_form.isNewRecord() returns true.



you can use GlideModal to get a bootstrap looking modal and it works the same as GlideDialogWindow.



also there is a way to set the content directly in a   glidemodal without using a uI page, but not at my computer so I can't remember the function call for it.   It might be setContent () or setBody().