Opening a dialog window from a button in a UI macro?

TE2
Kilo Contributor

Hi all, I'm a bit of a newbie with ServiceNow and am creating a catalog item in which there is (or rather, should be) a button that, when clicked, opens up a pop-up box with some information. I did not want to create an alert or use the already provided "More information" function. I am trying to write a script in my UI macro that would open this dialog window from the button. Here's what I currently have:

<html>

<head>

      <script>

             

              window.onload = function() {

                  var a = document.getElementById("myUIpageName");

                  a.onclick = function() {

                      function dialog() {

                              var dialog = new GlideDialogWindow("myUIpageName"); //Instantiate the dialog containing the UI Page 'add_comments_dialog'

                              //dialog.setTitle("Eligibility"); //Set the dialog title

                              //dialog.render(); //Open the dialog

                              //gs.log('test', 'myUserName');

                              alert('Test');

            }

                      return false;

                  }

              }

      </script>

</head>

<body>

      <a id="myUIpageName" class="request_catalog_button" style="width: 150px; height: 25px;">TextOnMyButton</a>              

</body>

</html>

Thanks!

1 ACCEPTED SOLUTION

ahaz86
Mega Guru

UI Macro:


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <input type="button" onclick="openDialog()" value="Open Dialog" class="selected_action action_context btn btn-primary"/>


  <script>


  function openDialog(){


              var dialog = new GlideDialogWindow("myUIpageName");


              dialog.setTitle("Eligibility");


              dialog.render();


  }


  </script>


</j:jelly>


View solution in original post

5 REPLIES 5

kavishree
Tera Contributor

Hi everyone,


I have some problem while submitting the record.


The dialog box is not getting closed when i cancel the form.


Client Script in UI Page:


==================


function onCancel() {


var c = gel('cancelled');


c.value = "true";


  GlideDialogWindow.get().destroy(); //Close the dialog window


    g_form.setValue("comments","hai");


}


Can anyone please help me to solve this.



Thanks,


Kavishree S