Login Terms and Conditions Dialog

//Login Terms and Conditions Dialog

Login Terms and Conditions Dialog

ServiceNow provides various methods for logging users into an instance. Local login, LDAP, SAML, and Digested Token are all used pretty regularly by customers. One thing that is often requested, but usually not successfully addressed, is the need to have the logged-in user accept some terms or conditions of use before they are allowed to use the system. The solutions attempted before usually suffered from a variety of issues ranging from overly-complex modification of one or more installation exits to being able to easily bypass the terms page entirely. In the end, these solutions seemed to be broken on some level. As we’ve seen requests for this type of functionality increase over the past few months, Jacob Andersen (who developed almost all of the integration and SSO information at SNCGuru) and I decided to collaborate to create a solution that actually works!

Login Terms Acceptance

This solution is loosely-based on another SNCGuru idea you might have used before…the Terms and Acceptance Dialog. If you are looking for a terms dialog for use with a specific catalog item or form within your instance you should take a look at this post instead.

Features:

  • Use the same way no matter what authentication method you’re using!
  • No messy, complex modifications of installation exits
  • Dialog-based acceptance page ensures no interference with user login or deep-linking
  • Complete logging of each user interaction with the dialog
  • Use of properties and message to disable or enable the terms page at whatever interval you want, set logging level, and customize the dialog text
  • Multi-language, multi-company support built-in

Components and Usage:

This functionality is NOT intended to provide any additional level of security to your instance. A person with the right knowledge could bypass this dialog but they would still have to be logged into the system to do so. We’ve made it much, much easier just to click the ‘Accept’ button in the dialog rather than continually try to bypass the dialog on every single page refresh.

This SNCGuru solution is packaged as an update set for easy installation in your instance. Included in the update set are the following elements…

  • TermsAcceptance UI script – This global UI script is what initiates the entire process. When a user attempts to view any page in the system, the UI script runs and makes a call to the ‘TermsAcceptanceAjax’ script include to see if terms have been accepted for the user session. If not, the UI script triggers a dialog with the terms.
  • TermsAcceptanceAjax Script include – Does most of the heavy-lifting in the background to check user terms acceptance for a session and set and record acceptance and cancellation by each user as it happens.
  • terms_acceptance_dialog UI page – Contains the dialog contents that are displayed to the user and calls back to the ‘TermsAcceptanceAjax’ Script include to record and log terms acceptance details. Dialog logo image is dynamically pulled in based on the user’s company.
  • terms_acceptance.message Message record – Accessed by navigating to ‘System UI -> Messages, this message contains the actual text of the terms dialog. Simply add whatever HTML you want to this message record to modify the text of the dialog. Use of a message record for the text allows for multi-language support as well.
  • ‘Frequency (in days) that users must accept terms’ (terms_acceptance.interval) and ‘Log level of Terms/Acceptance page’ (terms_acceptance.log) system properties – These can be found under the ‘System Properties -> Terms Acceptance’ module. ‘terms_acceptance.interval’ allows you to disable the terms page completely or enable it to trigger at any daily interval. Use ‘-1’ to disable the terms page, ‘0’ to enable for every session, or any other daily interval as necessary. ‘terms_acceptance.log’ controls whether you log user acceptance, cancellation, both, or none of the above in the ‘Terms Acceptance’ table
  • IMPORTANT: Any ‘terms_acceptance.interval’ property value other than ‘-1’ or ‘0’ requires acceptance logging to be enabled in order to work properly!
  • Terms Acceptance table – Logging table for all user interactions with the terms dialog. If the ‘terms_acceptance.log’ property is set to log user interactions, they will be stored in this table. The ‘Terms Acceptance’ table can be accessed by navigating to ‘System Logs -> Terms Acceptance’
  • Flashcanvas UI script

You can view the update set and installation instructions here…

Related Links:

By | 2018-07-09T14:59:56-06:00 October 12th, 2011|Categories: System Definition|Tags: , , , , |29 Comments

About the Author:

29 Comments

  1. Rob Woodbyrne November 17, 2011 at 10:37 pm - Reply

    Nice!

  2. Josh Andres December 6, 2011 at 1:35 pm - Reply

    Mark, I’d love to utilize this but we are running into an issue. When logging in it fires for users with an admin role, for all other roles it bypasses it and doesn’t fire until they try to pop open a new window or tab. Any idea what object might be firing between the user login and the UI script that kicks off the Terms and Acceptance process. Any suggestions would be greatly appreciated

    • Mark Stanger December 6, 2011 at 2:32 pm - Reply

      Thanks for the feedback. I think I can reproduce the issue but it would help if you could clarify a couple of things for me. Does the issue occur for users with roles (like itil) or just for users with no roles at all? Also, does the issue occur if you use the CMS portal? https://yourinstance.service-now.com/ess

      My testing shows that this only happens for end users (those with no role at all) and that it only happens in the regular interface, not in the CMS interface.

      • Josh Andres December 6, 2011 at 2:47 pm - Reply

        Mark,

        Thanks for your quick response. It seems to affect everyone that is not a full admin. However when I used the CMS portal it did pop the terms and conditions as expected. We’ve tried various different role combinations and have not had it successfully fire except when they have the role “admin”.

        • Mark Stanger December 6, 2011 at 5:45 pm - Reply

          I think I’ve got a fix. What I discovered is that the system loads its outer frame differently for users with no roles. This required me to modify how the dialog selects the frame it should be displayed in. The required behavior now is to load the dialog in the main inner content frame when the system is displayed in the standard frame set. You should be able to fix your issue by pasting this code into the ‘TermsAcceptance’ UI script. I’ve added a new update set to do the same. Please let me know how this works for you.

          addLoadEvent( function() {
             //Ensure that we call the dialog for the correct frame
             if(window.frameElement){
                if(window.frameElement.id == 'gsft_main'){
                   checkTerms();
                }
             }
             else if(!window.frameElement){
                if(!$('gsft_main')){
                   checkTerms();
                }
             }  
          });

          function checkTerms() {
             //See if the user has accepted terms for this session
             var ga = new GlideAjax('TermsAcceptanceAjax');
             ga.addParam('sysparm_name','getSessionVariable');
             ga.addParam('sysparm_var_name','agreed_to_terms');
             ga.getXML(getTermsAcceptanceFromSession);
          }

          function getTermsAcceptanceFromSession(response) {
             var answer = response.responseXML.documentElement.getAttribute("answer");
             //If no terms acceptance display the dialog
             if (!answer){
                showTermsDialog();
             }
          }

          function showTermsDialog(){
             //Initialize and open the Dialog Window
             //Render the dialog containing the UI Page 'terms_acceptance_dialog'
             var dialog = new GlideDialogWindow('terms_acceptance_dialog');
             dialog.setTitle('Terms and Conditions'); //Set the dialog title
             dialog.setSize(500,400); //Set the dialog size
             dialog.removeCloseDecoration(); //Remove the dialog close icon
             dialog.render(); //Open the dialog

             //Customizations for dialog background color and opacity
             var d = $('grayBackground');
             d.style.opacity = "1"; //Opacity setting for normal browsers
             d.style.filter =  "alpha(opacity = 100)"; //Opacity setting for IE
             //d.style.backgroundColor = "blue"; //Optional background color setting
             //d.style.backgroundImage = "url('http://sncguru.com/logo.png')"; //Optional background image setting

             //Automatically adjust the size of the dialog as window dimensions change
             Event.observe(window, 'resize', function() {
                var dims = document.viewport.getDimensions(); // dims.width and dims.height
                d.style.width = dims.width + 'px';
                d.style.height = dims.height + 'px';
             });
          }
  3. Andrew Irwin April 30, 2013 at 10:10 am - Reply

    I’m using the login terms, and everything works great. However I’m trying to get the login terms to either fill the entire right pane, or the entire page? Based on the no role issue above it appears that maybe I could just call to a different frame?

  4. Jeff Jefferson November 12, 2013 at 8:53 am - Reply

    Mark, have you tried this on the Dublin release? I just found the script, looks cool and something we might utilize, I loaded it on our Dublin instance and it just comes up with dialog box and says loading and goes nowhere.

  5. Rob Nijbroek April 16, 2014 at 9:58 am - Reply

    Mark,

    your solution is exactly what i need but it is not running on the Dublin release. any hints on how to solve this?
    thanks

    • Mark Stanger April 16, 2014 at 11:11 am - Reply

      I just installed this on demo003 and it’s working fine there. Have you tried installing the solution on a SN demo instance?

  6. Shakti April 29, 2014 at 8:14 am - Reply

    very nice.. used it for slightly different requirement, your package was very useful

  7. nikkib May 12, 2014 at 3:13 am - Reply

    My colleague has used this and it works fine however we need to refine further to display with the CMS portal. The issue being that the portal is https://nstance.service-now.com/solveit and the logo for this is held within Content Management > Headers > solveIT – Header

    can you provide any guidance how I may be able to adapt this further to check for this.

    I have checked with a user who has no roles, and signed into the ess portal and it doesnt display the popup – even with the main company logo.

    many thanks

    • Mark Stanger May 12, 2014 at 11:49 am - Reply

      Hello, I’m confused as to the exact issue you’re having. It sounds like you want to pull the logo from the CMS header (you’ll have to query for the header record to get to that but it’s probably better in a separate system property). It also sounds like it might not be showing up at all in the CMS? I’ve confirmed that to be working in the past so I’m not sure what the issue might be there. You might try it in a SN demo instance and see if it works there.

      • nikkib May 23, 2014 at 8:58 am - Reply

        just to let you know that we fixed this – it was something that we had added internally which was causing the issue

        regards
        Nikki

  8. Marc October 15, 2014 at 2:48 am - Reply

    When the user has configured the ‘new UI’ with the edge to use a flyout page, this flyout overlays the acceptance dialog. The dialog is within the main frame (at z-index 1000) and the flyout is outside the main frame (at z-index 900).
    Any ideas on getting the dialog on top of the flyout ?

    Marc

  9. Faizeal October 15, 2014 at 8:44 am - Reply

    Hi Mark,

    I am using this terms and acceptance its working perfect.One quick question, Some time we dont want to show the terms message, in that time we are updating the terms.message with empty content.,but it is visible to users with “term.acceptance.message”
    can we handle any condition for messages like if message is empty not shown the pop up ? Is it possible? Please help on this.

    Thanks,
    Faizeal

  10. Sarah December 9, 2014 at 9:53 am - Reply

    Hi Mark,

    Having the same issue someone else mentioned earlier where terms and conditions dialog tries to load when the login screen is hit and just hangs and indicates it’s loading preventing the ability to login. Any ideas why it’s calling the UI page prior to login?

    Thanks,
    Sarah

  11. Daryll February 5, 2015 at 3:24 am - Reply

    Hi Mark,

    First of all this is really handy thank you.
    However I have one issue with it. We get a constant loading page if the user is not already logged in.
    Is there a way to delay this loading until the user has logged in.
    We use the out of the box login screen not SSO.

    Thanks,

    Daryll

    • Mark Stanger February 5, 2015 at 5:47 am - Reply

      Hi Daryll. This solution uses ‘gs.isLoggedIn’ to determine if the user is authenticated or not and prevent this issue. You’ll see this in the ‘TermsAcceptance’ script include. It has worked in the past, but it looks like ‘gs.isLoggedIn’ isn’t returning a correct value any more. You’ll want to contact ServiceNow to see about a fix for ‘gs.isLoggedIn’.

  12. Göran Lundqvist January 16, 2016 at 1:54 pm - Reply

    Hi Mark,

    I’m wondering if you have tested this on Geneva. I took your update set and installed on my developer instance and nothing happens when I log on. Nothing special in the logs either 🙁

    With regards,
    Göran

    • Göran Lundqvist January 16, 2016 at 2:27 pm - Reply

      Nevermind that question, It’s working now. I think it was another of my test ui script that stopped somehow this as well..

      Thou another problem happens, I got the same problem as daryll above. It hangs at the loading screen… problem is, how can I now turn it off… since I cant log in…;(

    • Julian Hoch February 3, 2016 at 2:08 am - Reply

      Hi, to get it to work properly on Geneva I had to do the following to things:
      a) change the load-function in the UI script, so the dialog is not trying to load on the login page by adding:
      // if not logged in, don’t call
      if (g_user.getUserName() == “guest”) {
      return;
      }

      b) change the function getTermsAcceptanceFromSession so it does a string comparison with “TRUE”:
      //If no terms acceptance display the dialog
      if (answer != “TRUE”){
      showTermsDialog();
      }

      Still there are some glitches, the dialog windows is displayed twice (the first time, it disappears againg after the home page starts to load). I’ll continue testing.

      • Mark Stanger February 3, 2016 at 7:54 am - Reply

        Thanks Julian! I’ve incorporated this into the download script.

  13. Badrul Hisham February 2, 2016 at 10:06 pm - Reply

    Hi Mark,

    Just what I was looking for to implement in our instance. However I had 1 small issue, is there a way to cancel the intervals, I just want users to accept the terms once. If a user already accepted it will not ask again ever.

    • Mark Stanger February 3, 2016 at 7:49 am - Reply

      I think all you would need to do is to set the terms acceptance property for frequency to a very large number of days.

      • Badrul Hisham February 3, 2016 at 7:37 pm - Reply

        Hi Mark,

        I tried this on a developer instance however I’m having an issue when I changed the terms & condition messages. When I logout and tried to login to the instance again the login screen was replaced with the Terms & Condition dialog box, however the dialog box does not show any messages just a loading animation and there’s no Accept / Cancel.

        No I can’t do anything with the instance and I’m forced to reset it. I’m now afraid to deploy it on my live instance.

        You can check the error screenshot below in the link
        https://drive.google.com/file/d/0BzYvxe7sPU3eMWt1X1NnUENqY3M/view?usp=sharing

        • Badrul Hisham February 3, 2016 at 11:22 pm - Reply

          Hi Mark,

          Nevermind, I’ve use the fix Julian Hoch provided and it’s working now. I’m on Fiji by the way.

          Thank you Julian Hoch for your solution.

  14. Dave Myers June 19, 2017 at 12:25 pm - Reply

    We are running into an issue where this Terms box is appearing when exporting reports to PDFs. Has anyone seen this issue?

Leave A Comment