您的位置:首页 > 运维架构

GlideDialogWindow: Popup Record List

2019-01-11 16:11 162 查看

https://www.servicenowguru.com/system-ui/glidedialogwindow_popup_record_list/


‘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();
}

You can also size any ‘GlideDialogWindow’ object by using the ‘setSize(WIDTH,HEIGHT)’, ‘setWidth(WIDTH)’, and ‘setHeight(HEIGHT)’ methods. For example, to set the width of the dialog above to 600 pixels, I could add ‘w.setWidth(600);’ at any point before rendering the dialog.

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>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Popup Record List