Display Pop-up terms and conditions on Login Service Portal

Victor Mesa
Tera Contributor

I would like to know if anyone know the step by step procedure on how I can create a login popup message from scratch?

I wanted the users to agree to our "Terms and Conditions" upon logging in the instance and store their responses in ServiceNow. 

 

Thanks,

5 REPLIES 5

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Victor Mesa ,
I trust you are doing great.

  1. Create a UI Page: Navigate to System UI -> UI Pages and click "New". Name the UI Page and add HTML code to display the login popup message.

  2. Create a UI Script: Navigate to System UI -> UI Scripts and click "New". Add JavaScript code to handle the user's response to the popup message.

  3. Create a UI Macro: Navigate to System UI -> UI Macros and click "New". Add the UI Page and UI Script to the macro.

  4. Configure the Login Page: Navigate to System Properties -> System UI -> Login and add the UI Macro to the "Login Page Content" field.

  5. Create a new table: Navigate to System Definition -> Tables and click "New". Name the table and add fields to store user responses.

  6. Create a Business Rule: Navigate to System Definition -> Business Rules and click "New". Set the "When to run" field to "Before" and "Insert" and "Update" operations. Add JavaScript code to validate the user's response and insert or update the corresponding record in the new table.

  7. Test the Login Popup: Log out of ServiceNow and log back in to test the login popup message and user response storage.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Okay @Amit Gujarathi,

 

Could you tell me the code of that UI Page, UI Script, UI Macro and Business Rule ??

 

 

Thanks and best regards

 @Amit Gujarathi, Please provide the snippet code  how to implement  below scenario 

Hi I want to display popup message(not alert message) related to major incident information , when user login to ServiceNow display in classic UI homepage. Please help me with process and scripts.

 

my question --> https://www.servicenow.com/community/itsm-forum/after-user-log-in-into-servicenow-i-want-display-pop...

 

Ex. pop message:

 

Hi Stephen, Please look into the Major incident<incident link> opened by <caller name>.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Victor Mesa ,
I have implemented something around like this in my project .,
Please look into below scripts 

UI Page Code

<!DOCTYPE html>
<html>
<head>
    <title>Login Popup</title>
    <style>
        /* Add your custom CSS styles here */
    </style>
</head>
<body>
    <div id="login-popup">
        <h1>Welcome to ServiceNow</h1>
        <p>Please read and accept our Terms and Conditions before continuing.</p>
        <input type="checkbox" id="agree-checkbox">
        <label for="agree-checkbox">I agree to the Terms and Conditions</label>
        <br><br>
        <button id="submit-button">Login</button>
    </div>
</body>
</html>

 

Client side code

function showLoginPopup() {
  var modal = new GlideModal('login-popup');
  modal.setTitle('Login');
  modal.setWidth(400);
  modal.setFooterButton('Submit', submitLoginPopup);
  modal.render();
}

function submitLoginPopup() {
  var agreed = document.getElementById('agree-checkbox').checked;
  if (agreed) {
    // Update user record with agreement status
    var user = new GlideRecord('sys_user');
    user.addQuery('user_name', g_user.getUserName());
    user.query();
    if (user.next()) {
      user.terms_agreed = true;
      user.update();
    }
    // Close the login popup and continue to the homepage
    var modal = GlideModal.getByElement($('login-popup'));
    modal.destroy();
    window.location.href = gs.getProperty('glide.entry.homepage');
  } else {
    alert('Please agree to the Terms and Conditions to continue.');
  }
}

// Show the login popup when the page loads
addLoadEvent(showLoginPopup);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi