Popup on login service portal

Geetika4
Mega Expert

Hi All,

I am want a popup every time I login to the instance. I know here , it is achieved for standard ui, but there are cases that end users when login to the instance are directly redirected to service portal, hence there I need similar popup as well.
This popup should be of confirm box type with two buttons "OK" and "Cancel"
If user selects cancel , he/she should be logged out.

I followed below steps to achieve this :
1. Created a widget
2. Added the widget to the /sp  index page through page designer

Widget client script is following 

function(spModal) {
	/* widget controller */
	var c = this;

	spModal.open({
		title: 'Info',
		message: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<p>
<p>Click the OK to proceed. If clicked Cancel you will be logged out',
		buttons: [
			{label:'Cancel'},
			{label:'Ok', cancel: true,primary: true}
		]
		
	}).then(function(){
		location.href='/logout.do';			
		
	})

}

Widget works perfectly, I need to just make it load/pop up only when user logins not evry time I visit the serviceportal homepage.

 

1 ACCEPTED SOLUTION

Geetika4
Mega Expert

Hello All,

I was able to find correct way to achieve my requirement, thanks to @ujjawalvishnoi and @Vaishnavi Lathkar who tried to help.

I am attaching my solution screenshot of widget for your reference. Also I have highlighted key points which were crucial for the solution to work.
find_real_file.png

View solution in original post

8 REPLIES 8

Vaishnavi Lathk
Mega Sage
Mega Sage

Hi

I have added a check so it will not run on login page. And changed to session variable so it will trigger each new login:

https://community.servicenow.com/community?id=community_article&sys_id=ca3f3c47db7edc504aa5d9d968961...

addLoadEvent(function () {
    var session = gs.getSession();
    if (session.getClientData('popup_triggered')) {
        return;
    }
    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;
    }

    session.putClientData('popup_triggered', 'true');


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

 

Hi Vaishnavi,

Thanks for your input, solution you provided would work for backend ui, while I am looking for service portal. Every time I login to service portal I want to show this popup.
If user selects cancel on this popup, he/she is logged out.

I am able to achieve latter part, while "every time I login" is something I am still figuring out.

It would be great if you can help me knowing how can I use same approach with the widget I have created.

Geetika4
Mega Expert

Hello All,

I was able to find correct way to achieve my requirement, thanks to @ujjawalvishnoi and @Vaishnavi Lathkar who tried to help.

I am attaching my solution screenshot of widget for your reference. Also I have highlighted key points which were crucial for the solution to work.
find_real_file.png