- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2016 10:39 AM
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!
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:39 AM
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>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2016 02:57 PM
I have something similar however I am using a UI Action to pop up a dialog to capture comments via a UI Page - maybe it will help?
UI Action:
Name - Add Comments
Table - Incident
Show on Update - checked
Client - checked
Form Button - checked
Onclick = showCommentsDialog()
Script:
function showCommentsDialog(){
var dialog = new GlideDialogWindow('Add Comments');
dialog.render();
}
UI Page:
Name - Add Comments
HTML - XML Section -
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<section class="textarea_holder">
<p>Please add comments</p>
<textarea rows="4" name="dialog_comments" id="dialog_comments" label="" value="" mandatory="true" class="form-control"/>
</section>
<br></br>
<section class="button_holder">
<button id="closeButton" class="btn btn-primary" type="submit" onclick="return validateComments()">Save</button>
</section>
</j:jelly>
Client Script Section -
function validateComments() {
//Make sure there are comments to submit
var comments = gel("dialog_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty, alert the user and stop submission
alert("Please enter your comments before submitting.");
return false;
}
//If there are comments, close the dialog window and submit them
GlideDialogWindow.get().destroy(); //Close the dialog window
g_form.setValue("short_description", comments); //Set the Short Description field with comments in the dialog
g_form.submit();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:51 AM
I was actually creating a catalog item. I forgot to mention that initially. Thank you though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:39 AM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2016 06:51 AM
Worked like a charm. Thanks so much!