- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:50 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 06:19 AM
@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.
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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 01:29 AM
Hi @Alon Grod
Please let me know where in the script you have made the popup. I want to have more clarity
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 04:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 10:35 PM
@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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2023 02:39 AM
@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'
});