why pop up does not come up when user login

Alon Grod
Tera Expert

Hi,

I have a requirement to raise a pop up when user login per session. The UI page functionality works fine but when the user login the pop does not come up

 

Screenshot 2023-07-28 at 10.49.28.png

Screenshot 2023-07-28 at 10.49.42.png

1 ACCEPTED SOLUTION

@Alon Grod To show popup after login page there are no suggested solutions. The only way is to create the global ui script and add the modal in that.

jaheerhattiwale_0-1690636545726.png

 

The issue with this approach is that the global ui script gets attached to all the pages we open in native ui. And the popup may open in all the pages.

 

So you need to restrict the popup to be visible only once using session. The functions putClientData and getClientData.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

12 REPLIES 12

piyushsain
Tera Guru
Tera Guru

Hi @Alon Grod 

Please let me know where in the script you have made the popup. I want to have more clarity

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Weird
Mega Sage

It works normally?
I was going to suggest checking the Script Include name and values.
Currently you're calling sessionUtil while the script include's name is SessionUtil.
Also inside your script include the var is sessionUtil. Try to change everything to SessionUtil first.

jaheerhattiwale
Mega Sage
Mega Sage

@Alon Grod Try adding the alert in the callback function. Alert the answer you received and check if the code is executing till that point or not.

If the alert is executed then try changing the showTerms function initialization like below

 

function showTerms(){

}

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@jaheerhattiwale  @Weird @piyushsain  im not getting any logs. The UI Page is working fine when I click on 'try it'. Im having problem with raising the pop up when the user login. I made some syntax adjustment to the code but still had no luck. Please help me to figure this

Processing script that calls script include:

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

function showTerms() {
    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
}

 

Script include:

var SessionUtil = Class.create();
SessionUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    handleSession: function(){
		
		gs.log('ALONSO');
		
        var session = gs.getSession();
		
        if(session.getClientData('popup_triggered')){
            return false;
        }
        session.putClientData('popup_triggered', true);
        return true;
    },
    type: 'SessionUtil'
});