GlideDialogWindow: Popup Record List

//GlideDialogWindow: Popup Record List

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

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>
By | 2018-07-09T15:00:07-06:00 September 13th, 2010|Categories: System UI|Tags: , , , , , |24 Comments

About the Author:

24 Comments

  1. Scott Brickell October 1, 2010 at 8:43 am - Reply

    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?

    • Mark Stanger October 1, 2010 at 8:52 am - Reply

      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.

  2. Scott Brickell October 4, 2010 at 1:15 am - Reply

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

    Thank you Mark

  3. Lofty May 23, 2012 at 4:57 pm - Reply

    I am using the Glide Dialog popup window to display tasks associated with the selected business service, but since Aspen release a little issue developed. When placing my mouse on the hoverover icon against the record in the Glide Dialog Popup window, the preview appears below the Glide Popup Window making it unusable. Is there a quick fix for this?

    • Mark Stanger May 23, 2012 at 8:34 pm - Reply

      Hmm, that seems strange. You really shouldn’t be able to hover over items in a glide dialog window at all. As far as I know, dialogs within dialogs aren’t supported. I think you should contact support on this one. Just don’t mention SNGuru or they’ll try to tell you it isn’t supported. 🙂

      • Lofty May 23, 2012 at 11:31 pm - Reply

        The strange thing is this used to work just fine, ultimately it is just a list of records displayed in a dialog. Without the hoverover preview, it makes the functionality almost useless and I might as well remove it. I will log a call with support, but surely there has to be a way to tell which window appears at the top.

  4. Jonathan Bledsoe September 17, 2012 at 3:51 pm - Reply

    I am having trouble with a popup for the user’s recent incidents. I want to display the last five incidents where the user is the caller. Everything works fine except that orderByDesc() does not seem to work in UI Macros and the same seems to be true for getRowCount(). This makes it very difficult to get only the last five incidents. I am having to run a GlideRecord Query before sending the query to the page so that I can find the 5th most recent date and include that in the query. Let me know if anyone has any ideas.

    function showCIIncidents(reference) {
    var call = g_form.getValue(‘caller_id’);
    var date=”;
    var gr = new GlideRecord(‘incident’);
    gr.addQuery(‘caller_id’,call);
    gr.orderByDesc(‘number’);
    gr.setLimit(5)
    gr.query();
    while(gr.next())
    {
    date=gr.sys_created_on;
    }

    //Initialize the GlideDialog window
    var query = ‘caller_id=’+ call+’^sys_created_on>’+date;
    var w = new GlideDialogWindow(‘show_list’);
    w.setTitle(‘Major Incidents’+date+’ ‘+query);
    w.setPreference(‘table’, ‘incident_list’);
    w.setPreference(‘sysparm_view’, ‘default’);
    //Set the query for the list
    var num = g_form.getValue(‘number’);

    w.setPreference(‘sysparm_query’, query);
    //Open the popup
    w.render();
    }

    • Mark Stanger September 17, 2012 at 7:38 pm - Reply

      I think the problem is that ‘setLimit’ and ‘getRowCount’ are only available server-side. You should be able to accomplish this, but you’ll need to use a GlideAjax call to do it.

  5. harsh October 2, 2012 at 11:50 pm - Reply

    In the first exmaple can we set the size of the pop up window.

    • Mark Stanger October 3, 2012 at 6:12 am - Reply

      You can. I’ve added a note to the article above explaining how.

      • Jonathan Bledsoe October 4, 2012 at 2:49 pm - Reply

        Mark

        The setSize(WIDTH,HEIGHT) works great in IE however I am unable to get it to work in any other browser. Is there another method we can use to set the size that will work across multiple browsers.

        Thanks

        • Mark Stanger October 4, 2012 at 9:28 pm - Reply

          I just tested it without issue when I responded to your post yesterday. If you’re having an issue with the API you’ll need to contact ServiceNow. I don’t know any other way than what I’ve posted.

          • Carleen March 6, 2013 at 3:04 pm - Reply

            Hi Mark, I know this post is a little old, but it appears that if you have a long string of text the GlideDialogWindow does not wrap the text despite using the setWidth method. The glide_confirm, glide_confirm_basic, etc all specifically have a nowrap tag in the cell that displays the text.

            We got around this by adding some table html code () to the beginning of our title preference:

            var dialog = new GlideDialogWindow('glide_confirm_basic', false);
            dialog.setTitle("The A-Team");
            dialog.setWidth(200);
            dialog.setPreference('title', "</td></tr><tr><td>Ten years ago a crack commando unit was sent to prison by a military court for a crime they didn't commit. These men promptly escaped from a maximum security stockade to the Los Angeles underground. Today, still wanted by the government, they survive as soldiers of fortune. If you have a problem and no one else can help, and if you can find them, maybe you can hire the A-team.");
            dialog.render();

            Hopefully this helps some additional people running into the width setting issue!

  6. Mahira March 21, 2013 at 7:17 am - Reply

    Hi Mark,

    The list that comes up donot have the usual list properties like sorting and export to Excel,pdf etc. Is it possible to enable these properties for this list?

    Thanks

  7. Monroe May 29, 2013 at 6:42 am - Reply

    Hi Mark,
    Is there a way to make an update to multiple records from the popup list that’s on a different table?
    I created an UI Action that’s only a list choice (titled, “Add Asset to Requested Item). When I popup my list (of assets) I want to be able to add any selected assets in that popup to the parent requested item. I’m having trouble doing this because I am unable to reference the sysID of the form/sc_req_item in my UI action.

    • Mark Stanger May 29, 2013 at 7:51 am - Reply

      There’s no way with a standard popup list that I’m aware of.

  8. Robert jokim August 28, 2013 at 6:01 pm - Reply

    I want a dialog popup from a UI action (or macro) showing a list of records. No drama so far.

    However, when I click a record from the table, I want this to populate a certain field (a reference field on the incident form) much like it would when opening the dialog from the magnifying glass icon. I can’t figure out this part! Any help would be greatly appreciated.

    • MG January 23, 2017 at 2:50 pm - Reply

      I’m looking for this functionality too.

  9. Divya April 18, 2017 at 12:05 am - Reply

    Hi Mark ,

    When we open the dialog box is it possible to set a dynamic filter so that we can see what we want.

    For ex i have this “Show Active Incidents” on the Requested for field in Incident,so when i click on this I will get all my Active incidents but is it possible that i can see others incidents too just by having a filter like we have a normal LIST.

    Thanks
    Divya

    • Mark Stanger April 18, 2017 at 6:01 am - Reply

      I don’t know of a simple way to do that with these methods currently.

  10. Alessandro May 11, 2017 at 1:18 pm - Reply

    Hi Mark,

    I’m trying to use this feature to show a popup with HR Profile but it always assume the last view used in the HR Profile form even though I’m forcing the use of another view. Do you have any idea on how to resolve this?

    • Mark Stanger May 11, 2017 at 1:37 pm - Reply

      If you’re forcing the view with a parameter as shown above and it’s not working then you’ve probably found a bug or some other configuration issue/conflict in your instance. You’ll probably want to talk to SN support to investigate.

Leave A Comment