Create a popup message upon login

jcpasia
Kilo Contributor

Hi,

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. 

 

I found some articles from SNGuru although it requires downloading a dialog which is no longer available.

 

Thank you in advance for the feedback!

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

You can save the result either in a table or for example as a user preference. I modified the ServiceNow Guru script below:

function termsOK() {
    //Gets called if the 'OK' dialog button is clicked
    //Make sure terms have been accepted
    var terms = gel('accept_terms').value;
    if (terms != 'true') {
        //If terms are false stop submission
        alert('Please accept the terms and conditions to continue your order.');
        return false;
    }
    //If accept checkbox is true do this...
    GlideDialogWindow.get().destroy(); //Close the dialog window
    if (!getPreference("user_accepted")) {
        setPreference("user_accepted", "true")
    }
}

function termsCancel() {
    //Redirect gets called if the 'Cancel' dialog button is clicked
    if ($('cancel_url').value != 'null') {
        window.location = $('cancel_url').value;
    }
    else {
        window.location = 'home.do'; //Redirect to default homepage
    }
}

View solution in original post

18 REPLIES 18

Willem
Giga Sage
Giga Sage

You can save the result either in a table or for example as a user preference. I modified the ServiceNow Guru script below:

function termsOK() {
    //Gets called if the 'OK' dialog button is clicked
    //Make sure terms have been accepted
    var terms = gel('accept_terms').value;
    if (terms != 'true') {
        //If terms are false stop submission
        alert('Please accept the terms and conditions to continue your order.');
        return false;
    }
    //If accept checkbox is true do this...
    GlideDialogWindow.get().destroy(); //Close the dialog window
    if (!getPreference("user_accepted")) {
        setPreference("user_accepted", "true")
    }
}

function termsCancel() {
    //Redirect gets called if the 'Cancel' dialog button is clicked
    if ($('cancel_url').value != 'null') {
        window.location = $('cancel_url').value;
    }
    else {
        window.location = 'home.do'; //Redirect to default homepage
    }
}

jcpasia
Kilo Contributor

Hi @Willem ,

 

I have replicated the steps you provided on the article.. however, I am currently encountering the message below every time I load the login page.

 

find_real_file.png

Oh that is an alert I did not remove in the UI script! I updated it in the article. The UI Script should be like below. After saving below, make sure you clear the cache or test in a new session in the browser. UI Scripts are cached, so otherwise old version would run.

addLoadEvent(function () {
    if ((window.name !== 'gsft_main') || (window.parent.document.URL.indexOf("login.do") > -1)) {
        console.log("Prevent popup in this window or on this page.");
        return;
    }

    var ga = new GlideAjax('global.sessionUtil');
    ga.addParam('sysparm_name', 'handleSession');
    ga.getXML(function (serverResponse) {
        var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
        if(answer == 'true'){
            showTerms();
        }
    });
});

var showTerms = function () {
    var dialog = new GlideDialogWindow('terms_and_conditions_dialog'); //Render the dialog containing the UI Page 'terms_and_conditions_dialog'
    dialog.setTitle('Terms and Conditions'); //Set the dialog title
    dialog.setSize(600, 600); //Set the dialog size
    dialog.removeCloseDecoration(); //Remove the dialog close icon
    dialog.setPreference('cancel_url', 'catalog_home.do?sysparm_view=catalog_default'); //Set optional cancel redirect URL
    dialog.render(); //Open the dialog
}

 

Let me know if this works for you.

jcpasia
Kilo Contributor

Thank you for the information @Willem !

 

Can we redirect the users to the "home.do" after clicking the Login button?

 

Upon simulation, they can skip the agreement by selecting any module from the filter navigator since the dialog box is only prompting on the Homepage.

 

And I also changed the cancel_url to logout.do

You can redirect back-end users to a different back-end page using 'glide.login.home'-System Property. In below example I redirect to incident.do after login:

find_real_file.png

Result after login:

find_real_file.png