SATURDAY, MAY 19, 2012

GlideDialogWindow: Popup Record List

I

‘ve been meaning to write about the different kinds of Glide popups available in Service-now for a while but haven’t really figured out a good way to show all of the different pieces that make them work. Instead of putting all of the information in one article I’ve decided to publish 2 or 3 different articles showing some of the different things I’ve done in the past. Look for more articles on Glide popup windows in the future. If you want to see all of the articles I’ve written about GlideDialogWindow and popups in Service-now just use the tags at the bottom of this article.
This article shows how you can pop open a list of records in Service-now using a couple of different methods. It also shows you how you could use a UI Macro icon to invoke either of these popup types.

The following scripts can be called anywhere where you can use client-side JavaScript. Most often these would probably be called from a UI Action with the ‘Client’ checkbox checked.

This first example shows how to pop open a list of major incidents in a GlideDialog window.

//Show Major Incidents in a GlideDialog popup window
function showMajorIncidents() {
   //Initialize the GlideDialog window
   var w = new GlideDialogWindow('show_list');
   w.setTitle('Major Incidents');
   w.setPreference('table', 'incident_list');
   w.setPreference('sysparm_view', 'default');
   //Set the query for the list
   var num = g_form.getValue('number');
   var query = 'active=true^priority=1^number!=' + num;
   w.setPreference('sysparm_query', query);
   //Open the popup
   w.render();
}

In some cases it may be necessary to open the popup in a separate window completely. This script opens a regular popup window containing a list of major incidents.

//Show Major Incidents in a Popup Window
function showMajorIncidents() {
   //Construct a URL for our popup window
   var num = g_form.getValue('number');
   var tableName = 'incident';
   var url =  tableName + '_list.do?';
   url += 'sysparm_query=active=true^priority=1^number!=' + num;
   //Open the popup
   var w = getTopWindow();
   w.popupOpenFocus(url, 'related_list',  950, 700, '', false, false);
}

You can also use these functions in UI Macros. Here’s an example that pops open a window displaying high-priority incidents currently open for the selected CI. The script would need to be put in a UI Macro and that macro would need to be added to the ‘cmdb_ci’ field.

UI Macros are associated to reference fields by using the ‘ref_contributions’ attribute on the dictionary entry for that reference field. So if I named this UI Macro ‘show_ci_incidents’ then I could add the macro to the reference field by adding ‘ref_contributions=show_ci_incidents’ as a dictionary attribute for the field. If I have more than one macro I need to add to a reference field I can add them by separating them with a semicolon like this… ‘ref_contributions=show_ci_incidents;macro_2;macro_3′
CLICK HERE if you need to see how to add a macro to a non-reference field.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <j2:if test="$[current.getTableName() == 'incident']">;
   <j:set var="jvar_n" value="show_major_incidents_${ref}"/>
   <g:reference_decoration id="${jvar_n}" field="${ref}"    
    onclick="showCIIncidents('${ref}')"
    title="${gs.getMessage('Show major incidents')}" image="images/warning.gifx"/>
  </j2:if>

<script>
function showCIIncidents(reference) {
   //Get the name of the field referenced by this macro
   var s = reference.split('.');
   var referenceField = s[1];
   //Get the value of the reference field
   var v = g_form.getValue(referenceField);

   //Initialize the dialog window
   var w = new GlideDialogWindow('show_list');
   w.setTitle('Major Incidents');
   w.setPreference('table', 'incident_list');
   w.setPreference('sysparm_view', 'default');

   //Set the query for the list
   var num = g_form.getValue('number');
   var query = 'active=true^priority=1^number!=' + num + '^' + referenceField + '=' + v;
   w.setPreference('sysparm_query', query);
   //Open the popup
   w.render();
}
</script>
</j:jelly>

Comments

Posted On
Oct 01, 2010
Posted By
Scott Brickell

Hey Mark,

I was trying the “GlideDialog popup window” for returning a list as you did above. I’ve got it working with the exception that I don’t have the ui action drop down menu and the check boxes for each record. Here is what I’ve got:

var dialog = new GlideDialogWindow('show_list');
 
dialog.setTitle('Crisis Events');
 
dialog.setPreference('table', 'u_crisis_list');
 
dialog.setPreference('sysparm_view', 'default');
 
var query = 'u_active=true'
 
dialog.setPreference('sysparm_query', query);
 
dialog.render();

Any suggestions?

Posted On
Oct 01, 2010
Posted By
Mark Stanger

Hey Scott,

Give it a try on /demo and see if you get different results. My guess is that you’re not using ListV2 but I’m not sure. Those elements aren’t anything that can be configured as part of the popup so it’s probably a larger system setting.

Posted On
Oct 04, 2010
Posted By
Scott Brickell

We do not have the ListV2 plugin installed, so I am sure that is what the issue is.

Thank you Mark

Leave a Reply


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Latest Comments

  • Jim Coyne: I’m not sure exactly what you are looking for, but can you use “window.location” in your...
  • Ian: Might want to check the single quotes around ITIL in the condition line, they gave an error for me until I...
  • Mark Stanger: That’s correct. This returns instance URLs. I don’t have an equivalent currently that...
  • ND: Hi Mark, This is very useful information. I am looking for similar method to find URL of a site created by us. We...