GlideDialogWindow: QuickForms

//GlideDialogWindow: QuickForms

GlideDialogWindow: QuickForms

A

couple of days ago I wrote about some cool ways that you can show system list information in GlideDialogWindow popups from a form. As promised, here’s another article showing some other ways that you can use GlideDialogWindow. 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.

In this article I’ll show you how you can use GlideDialogWindow to update records from a list with a multiple update or a form with an update or insert on a single record anywhere in the system.


Displaying a form popup from a form

Here’s an example I’ve used in the past that shows how you can use ‘GlideDialogWindow’ to show a popup from a form that you can use to update any record in the system (or make an insert into any table in the system). This example is a popup that shows required closure information when a UI action button is clicked.

1Create a new view on the table that has the form that you want to appear in the popup. For the new view you’ll just want to make sure that you include only the fields that are absolutely necessary to allow the user to make an update. In almost every case, your default form view will have way more information than is required. For this example I just added a few fields that would allow the user to enter resolution information about the incident.

2Create a UI action button that you can click to make the popup appear. Make sure to check the ‘Client’ checkbox and provide a value of ‘showMyForm()’ (or whatever the name of your ‘onclick’ function is) in the ‘OnClick’ field. For this example, I’ve added a condition of ‘!current.isNewRecord()’ so that the button doesn’t show up unless it appears on a valid record. Replace the reference to ‘ResolveDialog’ below with the name of your new view created in step 1 above.

‘Resolve Dialog’ UI Action
Name: Resolve Dialog
Table: Incident
Client: True
Form Button: True
OnClick: showMyForm()
Condition: !current.isNewRecord()
Script:

function showMyForm(){
   //Get the table name and sys_id of the record
   var tableName = g_form.getTableName();
   var sysID = g_form.getUniqueValue();

   //Create and open the dialog form
   var dialog = new GlideDialogForm('Update incident', tableName); //Provide dialog title and table name
   dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
   dialog.addParm('sysparm_view', 'ResolveDialog'); //Specify a form view
   dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
   dialog.render(); //Open the dialog
}

Thanks to the forums I also found that if you need to pass values into the dialog from your original form, you can set a callback function to pass and set those values into your dialog like this…

function showMyForm(){
   //Get the table name and sys_id of the record
   var tableName = g_form.getTableName();
   var sysID = g_form.getUniqueValue();

   //Create and open the dialog form
   var dialog = new GlideDialogForm('Update incident', tableName); //Provide dialog title and table name
   dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
   dialog.addParm('sysparm_view', 'ResolveDialog'); //Specify a form view
   dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists

   dialog.setLoadCallback(function(iframeDoc) {
   // To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
   var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;

   dialogFrame.g_form.setValue('close_notes', 'Hello world!');
   dialogFrame = null;
   });

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

3Since this form will include ALL of the buttons that normally display on the form, you’ll probably also want to add a client script that runs against the view you created and removes any unnecessary buttons. Typically you’ll just want to have the ‘Update’ button visible for something like this. An ‘onLoad’ client script that runs against your new view with a script like this should do the trick.

‘ResolveDialog remove buttons’ Client Script
Note that I’ve also added a couple of lines to set the value of the ‘Incident State’ field and make it read only. We don’t want people to modify the state from this popup form, but it needs to be set so that our UI Policy will display the closure fields and make them mandatory. Also note that I’ve used the ‘State’ field instead of ‘Incident State’ in my examples here. If you use ‘Incident State’ you’ll need to modify the script.

Name: ResolveDialog remove buttons
Table: Incident
Global: False
View: ResolveDialog
Type: onLoad

function onLoad() {
   //Set the incident state to Resolved
   g_form.setValue('state', 6);
   g_form.setReadonly('state', 'true');

   //Remove all buttons except for the 'Update' button
   var items = $$('BUTTON').each(function(item){
      if(item.id != 'sysverb_update'){
         item.hide();  
      }
   });
}

Here’s the end result. A simple, nice-looking form that allows you to make changes to any record in the system without navigating away from the record you’re currently viewing!

Displaying a form popup from a list (multiple updates with one action)

Here’s an example I’ve used in the past that shows how you can use ‘GlideDialogWindow’ along with the ‘showQuickForm’ method to show a popup from a list that you can use to update multiple records in a list with a single action.

The biggest drawback to this method is that it DOES NOT run client scripts or UI policies. Because of this, you’ll need to put a little more thought into exactly how you use it to present fields. It is also designed to ONLY work as a list action. The ‘showQuickForm’ method has also had some issues in the past (including a recent one with the ListV2 plugin). These issues have been resolved in the Fall 2010 Service-now release. If you’re seeing issues, chances are you need to upgrade.

1Create a new view on the table that has the form that you want to appear in the popup. For the new view you’ll just want to make sure that you include only the fields that are absolutely necessary to allow the user to make an update. In almost every case, your default form view will have way more information than is required. For this example I just added a few fields that would allow the user to enter assignment information about the incident.

2Create a UI action list choice menu option that you can click to make the popup appear. Replace the reference to ‘assignment’ in the condition below with the name of your new view created in step 1 above. You’ll also need to make sure that the ‘Action Name’ of your UI action matches the action name passed into your ‘OnClick’ function. Notice that I have ‘reassign’ for both the ‘Action Name’ and as a parameter going into the ‘showQuickForm’ function.

‘Reassign’ UI Action
Name: Reassign
Table: Incident
Action Name: reassign
Client: True
OnClick: showQuickForm(‘assignment’, ‘reassign’)
List Choice: True
Condition: gs.hasRole(‘itil’)
Script:

try{
   //Make sure State gets changed to 'Active'
   current.state = 2;
   current.update();
}catch(e){}

That’s it! There’s no need to remove extra buttons or form elements in this case. The ‘showQuickForm’ function takes care of that for you. You should be able to go to your record list, check a few records, and click the UI action choice option to see a popup that allows you to update multiple records with entries from your custom form in a single action.

By | 2018-07-09T15:00:07+00:00 September 16th, 2010|Categories: System UI|Tags: , , , , , , |104 Comments

About the Author:

Mark has worked in the IT industry since 2002 and with ServiceNow since 2007. He is the founder and creator of SN | Guru and the co-founder of Crossfuze, one of the worlds leading ServiceNow consulting partners. Prior to co-founding Crossfuze, he worked for ServiceNow as a Senior Architect on the Professional Services team. He has personally led dozens of successful implementations encompassing every part of the ServiceNow platform. He is also responsible for designing and developing groundbreaking ServiceNow solutions and best practices in the form of various applications, turnkey solutions, and integrations during his tenure at ServiceNow, Crossfuze and, of course, SN | Guru. These solutions are used today by ServiceNow administrators and consultants alike in hundreds of ServiceNow instances around the world!

104 Comments

  1. Scott Brickell September 17, 2010 at 8:15 am - Reply

    Great information Mark!

    Any thoughts on how to use this while ordering from the Service Catalog? In other words, you select a catalog item and when the screen loads, if any predetermined criteria is met, a user will be prompted for some unique information via a GlideDialogWindow.

    Currently, I’m doing this with a JavaScript prompt which is not necessarily very elegant.

    Many thanks,

    Scott

    • Mark Stanger September 17, 2010 at 8:18 am - Reply

      This specific method won’t help you to do this because it has to use a predefined form and doesn’t return any information back to the client when it’s done. I’m planning on writing an article next week hopefully that shows how to use custom UI pages in a popup to perform certain tasks. I think you’ll be able to customize that solution to do what you want.

    • Mark Stanger September 23, 2010 at 8:57 am - Reply

      Just wrote a post describing a method that you should be able to use to accomplish what you want. Here’s the link.
      https://www.servicenowguru.com/system-ui/glidedial

  2. Samantha September 22, 2010 at 5:39 am - Reply

    Is there any way to pass values from the form containing the UI action into the dialog window? In my usecase the dialog window is not a view of the current form- its a view of another form so its not going to bring over existing values.

    This part passes a sysID but I cant figure out how to pass other information off the original record.

    dialog.setSysID(sysID);

    I also posted this question on the community page.
    http://community.service-now.com/forum/4587

    • Mark Stanger September 27, 2010 at 12:43 pm - Reply

      I just discovered a solution that somebody figured out on the forums. I’ve documented it above but here’s the forum link as well.
      http://community.service-now.com/forum/4587

      • Scott Halverson May 13, 2014 at 9:50 pm - Reply

        Is there a way to populate or pass values but not have to go to a custom UI Page? For example I want to pass the incident number to set on the related record that is getting created by using glidedialogform(). I’m using the glidedialogform as an alternative to clicking ‘New’ on a related lists where the reference field is automatically populated.

        Thanks in advance.

        • Scott Halverson May 13, 2014 at 10:24 pm - Reply

          Figured it out, I had to reverse engineer the url parameters used when clicking the new button on a related list. Adding the below sysparms

          dialog.addParm(‘sysparm_collection’,’incident’); //table the glidedialogform is being invoked from
          dialog.addParm(‘sysparm_collection_key’,’u_task’); //the field that has the reference back to the incident table
          dialog.addParm(‘sysparm_collectionID’,sysID);// sys id of the incident record that we want to populate the u_task field with

  3. computerdr74 October 18, 2010 at 6:28 am - Reply

    Regarding multiple updates with one action…We have an ACL that prevents users from writing to the assignment group and assigned to fields if they aren’t a member of the current assignment group or if they aren’t the caller, etc. The issue is that we would like to allow an ITIL roled user to be able to multi-reassign or multi-resolve their tickets. They cannot do so with this ACL in place because the script references current which the quick form seems to have not context. Therefore, the ACL always returns false. (i.e. current.assigned_to == gs.getUserID();) How would one go about retaining the current security but also allow them to perform these multiple updates? I’ve tried everything I can think of without success.

    Thanks for your help!

    • Mark Stanger October 18, 2010 at 8:53 am - Reply

      I’m glad you’re finding a good use for this. I think that your problem is that the security IS actually working. With the multiple update solution, the form that loads as ‘current’ is actually an empty multiple update form. So when you load the form you have an empty value for all of the fields. What you need to do in your ACL is make sure that people can write to the field if the field is empty. You can do that in script for the assigned_to field by adding a check like this…

      answer = false;
       
      //Can write if user is assigned_to
       
      if(gs.getUserID() == current.assigned_to){
       
         answer = true;
       
      }
       
      //Can write if assigned_to is empty
       
      if(current.assigned_to.nil()){
       
         answer = true;
       
      }

      This script will be evaluated when your multiple update form loads (allowing all users to provide input to the form) and will also be run when the update to each record occurs (allowing write access to only the appropriate records). Give this a try and let me know how it works. I just tested it on my demo instance and it seemed to work fine there.

  4. Anonymous October 19, 2010 at 2:21 am - Reply

    Thanks for your quick reply. As you said, the security is working, which is great. My concern is that if I set it up the way that’s specified, which is one way I looked at it, users that we don’t want modifying these fields will be able to do just that. Putting it into context, we check the fields this way:

    answer = false;
    if (gs.getUser().isMemberOf(current.assignment_group)||
    current.assigned_to == gs.getUserID() ||
    current.opened_by == gs.getUserID() ||
    current.caller_id == gs.getUserID() ||
    gs.hasRole('u_incident_override') ){
       answer=true;
    }
    else{
       answer=false;
    }

    So, we don’t actually want the user to be able to modify the assigned_to or assignment_group fields unless one of the above conditions is met. Problem is that if we allow them to modify any incident that has an empty assigned to or assignment group, then that is considered a defect.

    Is there a way to bypass an ACL, possibly in the ACL itself or by creating a new ACL that will handle an empty multiple update form?

    Thanks for your input on this, it is greatly appreciated!

    • Mark Stanger October 19, 2010 at 2:33 am - Reply

      The only other thing I can think of right now would be to go ahead and open your security up a bit to allow for them to write to the field but add a business rule check to abort the record submission if the tightened security requirements weren’t met…specifically if the value changed from NULL to something else. This way they could still write to the multiple update form, but the update to each record would be evaluated individually for those records that started out with NULL values. Here’s another article I wrote describing how you could implement a server-side abort in a business rule.
      https://www.servicenowguru.com/scripting/stopping-

  5. computerdr74 October 19, 2010 at 3:02 am - Reply

    Yep, got it. Thought about this, too. I will run this past them to make sure this is feasible. I know when I first asked them about this they were hesitant to allow the fields to be editable in the first place. They were concerned that it was deceiving. Let me check into this and see if they would be satisfied with this approach.

    Thanks!

  6. Amy November 29, 2010 at 11:11 pm - Reply

    Hi Mark, I am trying to use GlideDialogForm to create a new record on click on UI action. The pop up opens and the record also gets created. However, if the user wants to close the pop up without submitting the form pop up, the close (x) icon gets hidden in internet explorer. It works fine in Mozilla. I thought of creating a Cancel button to close the pop up, but could not find how to use destroy() function on GlideDialogForm. Any clue on how to make pop up header visible in IE?

    • Mark Stanger November 29, 2010 at 11:24 pm - Reply

      Hey Amy,

      This really sounds like a bug of some sort. The first thing I would do is test the exact same setup at https://demo.service-now.com and see if the problem still exists there. If it does then you’ll want to contact support about the bug. If it doesn’t, then you’ll want to contact support about an upgrade.

      The default GlideDialogForm is pretty locked down so I’m not sure there’s much you can do. You might be able to set up an onLoad script for that specific form view and override the function that gets executed when the submit button gets clicked. You might also be able to set up your own custom dialog window as shown here.

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

      • Amy November 30, 2010 at 12:31 am - Reply

        Thanks Mark!

        I could resolve the IE problem by using

        dialog.setLoadCallback(function() {
         
        dialog.moveTo('20', '40');
         
        });

        Now, when I submit the form, the parent form gets refreshed which I do not want. I observe that there is sysparm_refresh parameter which gets set as sysparm_refresh=refresh. Is there any way I can stop refreshing the parent form? Also, is there any function like removeParm or deleteParm like addParm?

        • Mark Stanger November 30, 2010 at 4:11 am - Reply

          There’s no ‘remove parameter’ function that I know of. I still think this is a bug that you should report to support since it works in Firefox.

  7. Tony Nelson December 9, 2010 at 6:47 am - Reply

    Mark,

    I’m trying to use your code to pop a dialog form to allow level one to enter a user record. I’m getting a pop-up to appear that has the title on it but the form has not fields present and down not expand past the title bar. Below is the code I’m using…I believe the issue I’m experiencing is because I’m changing tables from the incident table to the sys_user table. I thank you in advance for any assistance you could provide.

    function showMyForm(){
     
       //Get the table name and sys_id of the record
     
       var tableName = g_form.getTableName();
     
       var sysID = g_form.getUniqueValue();
     

     
       //Create and open the dialog form
     
       var dialog = new GlideDialogForm('Add a Contact',tableName); //Provide dialog title and table name
     
       dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
     
       dialog.addParm('sysparm_view', 'adding_a_contact'); //Specify a form view
     
       dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
     
       dialog.render(); //Open the dialog
     
    }
    • Mark Stanger December 9, 2010 at 7:34 am - Reply

      If you’re triggering this from an incident record and the popup should show a form for a user record then you need to change the ‘tableName’ and ‘sysID’ values. The ‘tableName’ value should point to ‘sys_user’ and ‘sysID’ should be ‘-1’. Just change the first 2 variable lines in the script to these values and it should work better.

      • Peter Oneppo December 31, 2010 at 10:02 am - Reply

        Mark,

        I’ve made it so that while a user is entering an Incident, they can bring up the caller’s record to update it. Everything works great except that when the user clicks the ‘Update’ button on the popup, the incident is reloaded and any unsaved information is lost. How can I make it so that the ‘Update’ button for the User form has no affect on the Incident form?

        Thanks,

        Peter

        • Mark Stanger January 4, 2011 at 3:58 am - Reply

          Hey Peter,

          I’m not sure of a way to do that with a quickform. You’re probably better off in this case to pop open a new window for the record insert/modification you need. You can call ‘popupOpenStandard(url)’ from any client script and open up a new window that will allow a save without impacting the base form. You just need to construct the URL and pass it in.

  8. Tony Nelson December 10, 2010 at 12:47 am - Reply

    Mark…you rock! That worked perfectly. Thanks for the help.

  9. Nikita January 17, 2011 at 10:56 pm - Reply

    Hi Mark

    I removed the buttons from glidedialog pop-up but have troubles removing UI Actions known as Links (Related Links). They are displayed in GlideDialog window and I want to get rid of them there. Can you please give me a hint? I was thinking about checking the view name in UI Action Condition but could not find any method that can do that.

    • Nikita January 18, 2011 at 12:37 am - Reply

      This is a piece of client script that helped me removing Related Links UI Actions from GlideDialog pop-up:

      var refs1 = document.getElementsByClassName('related_links_container');
       
      //Remove Realted Links UI Actions from the form
       
      if (refs1) {
       
         for (i=0; i < refs1.length; i++) {
       
            var ref1 = refs1[i];
       
            inner = ref1.innerHTML;
       
            if (inner){
       
               ref1.style.display = 'none';
       
            }
       
         }
       
      }
  10. VincentB January 19, 2011 at 1:22 am - Reply

    Hi Mark,

    First, thanks for this article.

    I have a question concerning the fields presents in the ‘ResolveDialog’ view. Indeed, in the article you only use out of box fields and the size of the popup is automatically adapted to the view form.

    Nevertheless, I’m trying to use manually created fields in my view (u_solution for example). When adding it to the view, the size of my popup is not adapted and i have to use scrollbar to see all my fields…

    Do you have any ideas on how to solve this problem? (change the size of the form?, Change a property in my fields?, …)

    Thanks in advance,

    Vincent

  11. VincentB January 19, 2011 at 2:14 am - Reply

    Thanks for your quick answer Mark!

    I already had a look to the post you just linked to me, and tried to use the setSize property on my GlideDialogForm object. Nervetheless this property seems not working correctly if it is not on a glidedialogWindow. Indeed only the width of the popup changes, and even if the popup is larger, the scrollbar to move from left to right is still present because only the container’s width has increased and not the form.

  12. VincentB January 19, 2011 at 2:50 am - Reply

    Mark, I just find out why i had the problem. It came from an error in UI Policy. After a quick look, the setSize property is not necessary with the GlideDialogForm object and the window is automatically adapted.

    Thanks again and good evening !

    Vincent B

    • Michael D August 7, 2012 at 4:52 pm - Reply

      Vincent or Mark, I too am having an issue with the width of the dialog form, or rather the controls within the form. I’ve tried using the setSize property but like Vincent, the form expands as expected but the controls within the form remain restricted in size. They do not expand with the form.

      I’ve tried this in the demo16.service-now.com instance using a UI Action called “Test Dialog” when viewing an existing Incident form and it behaves as I’ve described.

      Vincent, what UI Policy error did you correct to solve your issue?

      Michael D.

      • Tim S December 30, 2014 at 3:31 am - Reply

        Hi,

        I have the same Issue, but I can´t find an error in any UI Policy. Could you please give us a hint where to look to solve this Issue?

        Thanks in advance,
        Tim

  13. JimC February 24, 2011 at 6:33 am - Reply

    I’m using this functionality to replace the “Add New Item” pop-up dialog on the Request form. I created a new view on the sc_req_item table and the dialog displays nicely for admin and itil users. However, I need ess users to be able to use the new form as well. The dialog appears, but uses the ess view instead of the new view. They are allowed to add items until they actually submit the request for approval (we’ve added a default Draft state to the request).

    Any reason why the new view is not displayed for the ess users?

    Thanks

    Jim

  14. JimC February 24, 2011 at 6:52 am - Reply

    I did use that post to override the sc_request table, but missed the sc_req_item section – thanks. Now I’m going to try to force the new view only for the popup and the ess view for the others.

  15. Brian Broadhurst February 28, 2011 at 7:35 am - Reply

    Hi Mark,

    I’m using this technique to capture Incident resolution details, as in your example. What we are finding is that when the pop-up is submitted (via the Update button), the parent form is redisplayed (not an issue), but in order to go back to the previous list view, we have to click the green back arrow twice – the first click redisplays the Incident form again. Same thing happens if after the popup, we click Update on the parent form – the parent form gets displayed again, then clicking Update a second time takes us back to the list view. Seems to me that the navigation stack is ending up with one more entry than we need. Any ideas how we can get around this?

    Brian Broadhurst

    • Mark Stanger February 28, 2011 at 9:31 am - Reply

      The only thing I can think of is to try setting the ‘sysparm_stack’ parameter when you render your dialog window or set up a UI action/Business rule redirect to handle this specific case.
      http://wiki.service-now.com/index.php?title=Navig

  16. JimC March 30, 2011 at 7:21 am - Reply

    I mentioned above that I’m using the popup to replace the “Add New Item” pop-up dialog on the Request form. I created a new view on the sc_req_item table and it is working nicely. However, the Short description field is showing up as Read-only for ESS users, BUT the field is writeable if you click on the item link in the related list below. I had to override the Access Control rules to allow it to be writeable, but it seems like it is not quite making it into the popup window for some reason but is fine in the “normal” form.

    • Mark Stanger March 30, 2011 at 8:42 am - Reply

      That is strange. Check your ACLs on ‘sc_req_item’ and ‘task’ for anything view-related. The only other thing I can think of that would do that is a UI policy or client script. If you can set up a test case and reproduce it on demo I’ll take a look.

  17. JimC March 30, 2011 at 9:38 am - Reply

    It’s definitely ACL based. I added some more ACLs to lock down the fields depending on the state of the Request and now all the fields are Read-only in the popup but editable in the real form. The field is editable if I deactivate the appropriate ACL.

    I’ll see if I can set something up in demo.

  18. JimC March 30, 2011 at 10:25 am - Reply

    I’ve added a “Test popup” UI Action to the Request table in Demo. I’m playing with it to see if I can duplicate the issue I’m seeing.

  19. JimC March 31, 2011 at 4:05 am - Reply

    For those who are interested, the problem was with the drill-through to the request record. This works fine if the item has already been created, but results in an invalid reference for a new item record since the item really did not exist. I modified the condition script in the ACLs and it now works perfectly:

    var answer = false;
     
    if(current.request.request_state == 'draft' &amp;&amp; (current.request.u_request_type == 'x' || current.request.u_request_type == 'y')){
     
       if(current.request.opened_by == gs.getUserID() || current.request.requested_for == gs.getUserID() || gs.hasRole('itil')){
     
          answer = true;
     
       }
     
    }
     
    if(current.isNewRecord()){
     
       answer = true;
     
    }
     
    answer;

    The check for the new record enables the fields in the popup window to be editable.

    Thanks for the help Mark.

    Jim

  20. Blair April 1, 2011 at 5:32 am - Reply

    How can I change name of the button on the pop window from the list view?

    • Mark Stanger April 1, 2011 at 7:11 am - Reply

      I’m not sure I follow. Is this a GlideDialogWindow question?

      • Blair April 1, 2011 at 7:20 am - Reply

        Yes, sorry I was a vague in my last post. I used the GlideDialogWindow Client script on a UI Action within a list. Instead of the word “Update” on the button, we want the word “Submit”. I see it’s defined under “sysverb_post_update”, but I don’t know where to change that.

        • Mark Stanger April 1, 2011 at 7:24 am - Reply

          The list popups aren’t really customizable. They don’t support client scripts on the forms they present so there’s not a way I know of to change the button text for that popup.

  21. Blair April 4, 2011 at 7:08 am - Reply

    Mark,

    Thanks for your help.

  22. Chris York April 25, 2011 at 7:39 am - Reply

    Mark, This worked great for me. In your example where you are using this to record Close Notes for an Incident, It would be nice to return back to the list of records instead of back on the Incident that you just updated with the GlideDialogForm. Is there a way to redirect to the list instead? Similar to just clicking update on the main form.

  23. Mark Stanger April 25, 2011 at 9:30 am - Reply

    You can set a completion callback right before the ‘dialog.render()’ line like this to do the redirect…

    dialog.setCompletionCallback(function() {
     
       window.location='incident_list.do';
     
    });
  24. Jason Thomas April 27, 2011 at 6:01 pm - Reply

    Hi Mark

    Instead of using the client script to remove the buttons, you can use the UI Action Visibility, to exclude the buttons from that view.

    Just a thought.

    • Mark Stanger April 28, 2011 at 12:08 am - Reply

      Thanks Jason,

      You’re exactly right. I wrote on the topic of form button removal before here…
      https://www.servicenowguru.com/scripting/client-sc

      UI action visibility is a great way to remove form buttons for specific views and it should definitely be strongly considered any time you remove form buttons. For this case where there may be 1 or 10 buttons to remove I kind of like to do it all in one spot with the client script but either way works great.

  25. Divya May 30, 2011 at 9:44 pm - Reply

    Hi Mark,

    I am using this code to create a pop up from a UI action(list choice). Here i am trying to use modify UI action and it opens up a pop up with few fields which i want to modify. But the problem i face is when i fill in those fields and click on submit a new incident record is getting created and the values are not getting updated to my required record Could you please help me out with this?

    This is the code i used

    var sysID = current.sys_id;  
     
    function showMyForm(){  
     
    //Get the table name and sys_id of the record    
     

     
       //Create and open the dialog form
     
       var dialog = new GlideDialogForm('Modify incident', 'incident'); //Provide dialog title and table name
     
       // dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
     
       dialog.addParm('sysparm_view', 'modify2'); //Specify a form view
     
       dialog.addParm('sysparm_form_only', 'true'); //Add or remove related lists
     
       dialog.render(); //Open the dialog
     
    }
    • Mark Stanger May 30, 2011 at 10:29 pm - Reply

      The problem is that you’re using code that is designed to be initiated from a form, not a list action. With a list action, you need to use the list code in this article.

  26. Michele King June 24, 2011 at 2:53 am - Reply

    I am using the GlideDialogForm to update the Priority and require notes on why the priority was changed. I want a Cancel button on the form so I can “cancel” the change instead of using the “X” in the top right corner. Any suggestions on how to destroy the form?

    Thanks-Michele

    • Mark Stanger June 24, 2011 at 7:54 am - Reply

      You’ll need to test this but you should be able to create a UI action just for that popup view to show a ‘Cancel’ button. The UI action would need to run a client-side function and leverage the ‘destroy’ method to close the dialog like this…

      GlideDialogWindow.get().destroy(); //Close the dialog window
      • Michele King July 22, 2011 at 11:46 am - Reply

        Got it. Actually I just have a cancel button (action = cancel) not client callable and just has the script

        action.setRedirectURL(current);

        and in the original UI Action which calls the dialog window, I added

        if (action == 'cancel') {
        dialog.destroy();
        }

        and that works perfectly.

  27. Joe July 21, 2011 at 12:34 pm - Reply

    When using showQuickForm() in a UI Action you must make it a client side script for the pop up, but the script is written like a business rule (for example, all I have in my script is current.update()). In my instance I’m seeing a javascript error on the list view “current not defined”, but if I don’t use current.update() the records don’t get updated. Any ideas on how to get around this so that the UI Action works and I don’t get any nasty errors?

    • Michael January 21, 2015 at 8:07 am - Reply

      I just encountered this same issue. The solution is to wrap the current.update() in a try/catch and not actually handle the catch.

      try {
      current.update();
      } catch(e) {}

      The problem is, since it’s a client side action, the script is added to the page when the page loads. Since there’s no reference at that point for “current”, the script fails and stops all further processing. By wrapping the method in a try/catch, the error still occurs but is not “caught” and therefore processing can continue.

      It’s actually documented that way in the code example above but not the image example. I modeled my UI Action using the image example and missed the try/catch part. Since I created a UI Action as a client side list choice, this wreaked havoc with homepages that included a list view.

      • Mark Stanger January 21, 2015 at 9:47 am - Reply

        Thanks Michael, this is exactly correct. Any use of this type of UI action in a list will require a try/catch around the server-side components.

  28. Vincent B August 23, 2011 at 7:03 am - Reply

    Hi Mark,

    I’m experiencing some issues since the high security plugin has been activated (before everything worked perfectly). Did you already tried this script on an instance with the High Secu Plugin?

    Thanks in advance,
    VincentB

    • Mark Stanger August 23, 2011 at 7:33 am - Reply

      I haven’t ever heard of any issues with the dialog related to the high security plugin. I just copied this example into my own personal instance (which has the high security plugin enabled) and I didn’t have any issues. The only thing I can recommend is to try to recreate the example given here exactly and see if that works and go from there.

  29. Daniel September 14, 2011 at 3:44 am - Reply

    Hi Mark,
    thanks for this awesome tip! Finally I was able to create a AJAX Popup within the Assign-To-Me function to enable the verification of the assignment group by the user.
    Best regards,
    Daniel

  30. Swaminathan October 20, 2011 at 12:10 am - Reply

    Do we have some way to hide close(X) button for the user,We need it in a scenario when we place some mandatory field in the quick form and we don’t want the user to escape the mandatory check by pressing the close button.

  31. Pratik November 28, 2011 at 4:05 am - Reply

    Hi Mark

    Can we have a Glide List embedded in a UI Page?
    If not what are the options we have for multi pick list on a UI Page?

    Thanks,
    Pratik

    • Mark Stanger November 28, 2011 at 6:01 am - Reply

      You can, but it can be difficult to get them to work just the way you want. There are UI macros in the system for both glide list (lightweight_glide_list) and slushbucket (ui_slushbucket). You can search the UI pages in the system for references to these macros to see how they are used.

  32. Jason January 18, 2012 at 5:47 am - Reply

    Hi Mark

    I’d like to have the window popup and then either use a submit button, which submits the record and closes the popup window (returning the user back to the initial record), or use an add another button which adds another record, but remains within the popup window.

    any ideas on how to achieve?

    • Mark Stanger January 18, 2012 at 6:25 am - Reply

      I don’t have an exact solution for you, but I think what you’re going after will be somewhat similar to the solution I’ve documented here.
      https://www.servicenowguru.com/system-ui/ui-macros/adding-referenced-records-leaving-form/

      • Jason January 20, 2012 at 1:48 am - Reply

        I have the popup etc working, the only part not working is the add additional button.

        The user needs to add multiple expenses via the sys_popup dialog.
        The user can currently submit a single expense record.

        I am using the same code as the insert and stay button, which I assume is where the problem lies, because its doing a submit, and thus calling the callback function.

        Is there a way to perform the insert but not return back to the record until either the submit button is clicked (already working) or the close button.

        Thanks

        • Mark Stanger January 20, 2012 at 5:40 am - Reply

          I’m not aware of a simple solution to that but you may ask on the forums.

  33. Bryan Barnard January 19, 2012 at 2:48 pm - Reply

    Is there a way to hide a reference icon on a form in this case the view I’m using in my QuickForm. My Quickform is quite small and only has one field ( a reference field) and the problem is that when a value is selected for the reference then the Reference Icon shows up. If the user hovers on that then due to the small size of my form it will become rather crowded. I would rather just eliminate the reference icon.

    I’ve tried client script via ‘Client Scripts’ and ‘UI Policies’ but it seems that the SN Script that runs to add the Reference Icon always runs after my client script so even if change the display to ‘none’ in mine the later running script changes it back to display.

    Thanks,
    Bryan

    • Mark Stanger January 19, 2012 at 3:17 pm - Reply

      The only way to do this is to remove the element completely because the field change logic for a reference field is designed to show the field every time you populate a valid value. Here’s a snipped you could use in a client script.

      Make sure to run the script ONLY for the popup view. You should just have to replace ‘incident.caller_id’ with the table and field name you’re using.

      $('view.incident.caller_id').hide();
  34. Bryan January 20, 2012 at 8:21 am - Reply

    Thanks!

    I tried using hide() but still had issues, switched to .remove() and it worked perfectly.

    $(‘view.incident.caller_id’).remove();

    • Mark Stanger January 20, 2012 at 8:24 am - Reply

      Ugh. I hope that didn’t cost you too much time. remove() is what I meant to paste in to give to you. I’m glad you’ve got it working.

  35. Bryan January 20, 2012 at 8:36 am - Reply

    only a couple mins. I had to read your comment twice because I read remove and then saw the example “hide()”, and thought i’m pretty sure he meant remove but I’ll tried hide just in case..

    thanks again

  36. Jason February 1, 2012 at 6:32 am - Reply

    Hi Marc

    Just thought I’d share an issue I was having, and the solution….

    I had created a UI macro which had a button element in it, that when clicked called the GlideDialogWindow.
    It worked perfectly in IE but was inserting empty records in firefox.

    It turns out that the button element in firefox was performing a submit action (default action in firefox, not in IE) and thus submitting the form.
    To fix, you need to add the type=”button” attribute to the button element.

    Cheers
    Jason

    • Mark Stanger February 1, 2012 at 7:22 am - Reply

      Great tip! I’ve had that same issue with buttons WITHIN dialogs as well. Took me longer than I wanted to figure it out :).

  37. Amir Karami March 27, 2012 at 3:01 pm - Reply

    Hi Mark,
    Is there any way to make the fields required required on popup form when using the “showQuickForm’ method?

    • Mark Stanger March 27, 2012 at 3:32 pm - Reply

      The list-based quickform can’t do mandatory fields. The form-based quickform just uses the client scripts and UI policies for that form view.

  38. Joe Jogmen June 20, 2012 at 8:04 pm - Reply

    This works to perfection, however I have a UI display question.

    The quickform dialog that is rendered is very narrow and appears to autofit my fields (from the view). I added a setSize which increased the quickform dialog borders, however, the actual field sizes were unchanged – and stayed their original narrow size.

    To give some context in lieu of an image, a 500 max len string only has a width that can support the following string on one line: “wordwordwordwordwordwordwordwordwordwordwordw”. This is as wide as the widest field on the dialog.

    If I look at my view natively (outside of this form) the fields are the typical size and span as I’d expect – so I don’t think its an issue w/the view.

    Is this something that can be overcome, or is it an artifact of the quickform dialog?

    Thanks as always.

    • Mark Stanger June 20, 2012 at 8:11 pm - Reply

      Hey Joe,

      Unfortunately, I’m not aware of any simple way to deal with that.

  39. Erite January 24, 2013 at 4:41 am - Reply

    Hi Mark,

    I wonder if you can help me:

    My requirement is on incident creation, a popup box, called ‘Log and Assign’ should appear to allow the Service Desk to enter the assignment group, the assigned to person and insert the record.
    How would you do this please?

    When I follow your instructions I get the error ‘Changes have been made, Continuing will discard the changes’. Basically the changes from the original form are not saved and clicking submit on the popup creates a new incident with only the assignment group and the assigned to person populated.

    Thanks in advance,

    Erite

  40. Faizeal March 26, 2013 at 9:50 am - Reply

    Hi Mark,

    I need one information. Is it possible to remove the tree_picker/Pop_up icon (refernce fields) based on roles?

    Because,end user cannot see the tree picker/Pop_up icon for reference fields,

    For Ex: location is a reference field. End users saee only the location text, cannot see the location details in pop up

    can we manage in client scripts?

    Please give some suggestion this.

    Thanks,

    Faizeal.

  41. Mark Sandner May 7, 2013 at 12:34 pm - Reply

    We use this on an Incident form, with a glide_date_time field on the popup form. This works fine in the Aspen release, but not in Berlin. The calendar just plain won’t show. I am curious if anyone else experienced this. Maybe a case to skip Berlin and go straight to Calgary….

    • Bryan May 21, 2014 at 3:57 pm - Reply

      It works great in Calgary but it’s broken in Dublin 🙁

      • Mark Stanger May 21, 2014 at 4:03 pm - Reply

        Contact ServiceNow if you’re having an issue with this. If there’s an issue and you can reproduce it in a ServiceNow demo environment, it’s with the dialog itself, which we don’t really have any control over.

  42. Harel March 11, 2015 at 9:16 am - Reply

    Hi Mark,

    I configured quickForm to allow a user to change priority of an incident. It works beautifully for users with roles, but not so much for ‘public’`- they get a blank pop up without the two fields I need to be displayed – urgency and impact.
    I was told this is an ACL thing- that I need to add appropriate record- and field- level read and write ACLs to open this up to public for this to work (and think about security considerations). So I added the ACLs for these two fields (incident.urgency and incident.impact), with read and write for public but still the fields are not even displayed in the pop up…
    So first, what do they mean by “record-level”?
    And second – any idea on how to proceed?

    Thanks
    Harel

    • Mark Stanger March 12, 2015 at 2:14 pm - Reply

      It should just be the ACLs you mentioned. ‘incident.impact’ and ‘incident.urgency’ are the ACLs you’ll need. If it’s public, you’ll probably also need to adjust the ‘incident functions’ business rule. That forces the ‘ess’ view for non-roled users so you might need to disable or adjust that as well. You can determine whether or not the popup is the issue just by opening the incident form with your popup view inside of a standard browser tab. If it doesn’t work there, then it’s a security issue as I’ve described here. If it does work in a standard browser tab then it’s probably some bug with the popup that you’ll need to contact ServiceNow about.

      • Harel March 23, 2015 at 3:20 am - Reply

        Hi Mark,

        Thanks for the answer.
        I will try it out and see what happens 🙂

        Harel

  43. Rose Mueller March 23, 2015 at 7:34 am - Reply

    I’m using this GlideDialogForm for our Major Incident process and it seems to have broke in Fuji. The form comes up fine, the mandatory fields work great but when the ‘Save’ button is selected nothing happens. I opened a ticket with SN HI and received the following answer.

    The reason this is occurring is because the code is using AJAXEvaluateSynchronously instead of GlideAjax. AJAXEvaluateSynchronously shouldn’t be used, please refer to this wiki page http://wiki.servicenow.com/index.php?title=GlideAjax.

    • Mark Stanger March 23, 2015 at 1:38 pm - Reply

      Rose, ServiceNow is correct regarding AjaxEvaluateSynchronously but I don’t use any of that here. I’m not sure where it may be used in your environment so you may need to work with ServiceNow some more on that. It’s not a core part of the dialog here though.

      • Rose Mueller March 24, 2015 at 3:23 pm - Reply

        Thanks for the response Mark, I looked at this closer today and realized that SN was looking at an old inactive client script. The issue happened to be another client script that had some AJAXEvaluateSynchronously code. Inactivating that client script allowed the major incident GlideDialogForm to work properly.

  44. Andreas December 4, 2015 at 2:08 pm - Reply

    Hi,

    There is a second way to pass in additional values.

    Add simply the following line to your code before calling dialog.render();

    dialog.addParm('sysparm_query', 'u_parent=' + g_form.getUniqueValue());

    This will pass in the sys_id of the current record to the field “u_parent” of the new record you are about to create.
    But you can pass in any value to any field. Best of all: The field does not have to be on the form (which is a pre-requisite when using g_form.setValue)

    Cheers!

  45. MA December 23, 2015 at 4:18 am - Reply

    Thanks mate you made my life easy. This is what i was looking for exactly.

    Really appreciate your effor

  46. Reed March 6, 2017 at 1:24 pm - Reply

    I’m doing something similar, except I’m not doing it from a UI Action. Under certain circumstances my customer wants it to become mandatory that at least one record be present in one of the related lists before an incident can be resolved. I wrote an onSubmit Client Script to check for the conditions and the presence of the related record. When the record is required but isn’t present, I want to allow them to create it via a default view pop-up form instead of making them create it by manually moving to the related record’s form thereby losing any updates they entered on the incident form. The problem I’m having is that the Client Script doesn’t wait until the pop-up form is submitted – and just goes ahead with the next statement after “render” even before the pop-up is displayed. So I can’t verify the new record got created. I can probably make this work by aborting the incident update and making the user re-submit it after the related record is created, but it would be cleaner if I could make the pop-up form “modal” and wait until the pop-up is closed to continue the Client Script processing.

    Below is the code I’m using. Any assistance would be appreciated.

        var sysID = g_form.getUniqueValue();

        if ([the conditions are present]) {

            if(!confirm('[Message to user that related record is required]')) return false;

            var dialog = new GlideDialogForm('Create Record', 'u_related_table');
            dialog.setSysID(-1);
            dialog.addParm('sysparm_view', null);
            dialog.addParm('sysparm_form_only', 'true');

            dialog.setLoadCallback(function(iframeDoc) {
            var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
            dialogFrame.g_form.setValue('u_incident', sysID);
            dialogFrame = null; });
            dialog.render();
        [I want it to wait here until the rendered pop-up is submitted or closed]
            var NoRelatedRecs = checkForRelatedRecs(sysID);
            if(NoRelatedRecs) return false;
        }
    • Mark Stanger March 6, 2017 at 4:06 pm - Reply

      The ‘checkForRelatedRecs’ check needs to be placed somewhere that it can be evaluated on Submit. You’ll probably need to move this back to the base table in an ‘onSubmit’ script or something.

  47. Reed March 7, 2017 at 2:53 pm - Reply

    Hi Mark,

    That part is working – in fact, it runs before the pop-up even comes up. I need a way to have it wait until the pop-up is submitted. That “checkForRelatedRecs” is just a function (that I didn’t include in the code snip-it) that makes a GlideAjax call to a script include via getXMLWait() to check to make sure they successfully created the related record. I can’t do that onSubmit because it was just created. If there is a way that I could have the pop-up return a value to my client script telling me sucsess/failure, then I wouldn’t need to call that function. I tried doing what MB describes here: https://community.servicenow.com/people/MB/blog/2011/03/23/2476, but an empty gray pop-up flashes very briefly and goes away. So I couldn’t get that to work (and besides, I need to pass the incident sys_id to the pop-up). Any other ideas?

    Thanks for reading.

    • Mark Stanger March 7, 2017 at 3:31 pm - Reply

      Exactly, that’s why I’m saying you’ve got to move that part to a different script location entirely. If it’s where you’ve put it you’ll always have it running too soon. I’m not sure what the rest of the setup looks like so it’s hard for me to be more specific about where to locate it.

  48. Regina Bautista June 14, 2017 at 6:48 am - Reply

    Hi Mark, great article thanks! I am currently using showQuickForm in my UI Action (list choice) and it’s working great. However we have a requirement to make fields mandatory on the dialog box not on the main form. How do I accomplish this considering the fields I am using in the dialog box is basically same fields that are available on the parent form? Please help. Thanks

    • Arnab Karak September 5, 2017 at 1:48 pm - Reply

      Have you got any solution with your requirement.

  49. sm August 17, 2017 at 4:57 am - Reply

    I tried to use the GlideDialogWindow for attachment popup, but instead of opening the window next to the event button, it opened it on the top of the page, so the user see blank page and can not see the popup window unless he scroll back to the top of the page.
    I really need help with it, do you have any solution for me?

    • Mila Morales September 11, 2017 at 11:37 am - Reply

      What version of instance are you using? If you are using the dialog for attachment only, I think he can use the UI action attachment which already OOB. Or if GlideDialogWindow has fields you can use “Focus” (javscript) on those fields.

  50. Arnab Karak September 5, 2017 at 1:47 pm - Reply

    Hey Mark,

    The above information was quite helpful.

    I was wandering can we set any field to mandatory in the view when someone clicks on the List Choice UI Actions ?

  51. sandeep September 29, 2017 at 8:14 am - Reply

    HI Mark,

    Thanks for the above solutions.
    My business case is different.

    We have to assign the incidents to a team, which has to update worknotes for each and every incident every day.
    Usually, they miss to update the worknotes , which are the source to navigate the statuses of the tickets assigned until they get closed.

    Can you provide an idea how can we get a pop up notification, which are customized with time.
    like Case1) 24hrs from the last Worknotes updated time.
    Case2) Time at which a pop up should come, (if worknotes not updated)

    Regards
    Sandeep N

Leave A Comment