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

Ujjawal Vishnoi
Mega Sage
Mega Sage

Add your code in script include SPEntryPage().getFirstPageURL().

So that it runs only first time.

Please see below documentation

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746730

Hope this helps.

Regards,

Ujjawal

Hi Ujjawal,

I went through the script include and its function , but still not sure how can I make my widget only load once from here.
Can you please more details how can I make it work. Also do I need to remove my widget from the page index 

find_real_file.png

 

 

You need not to create a separate widget. You need to add your logic to script include itself.

Have you done something like this before. I need to show a popup like this :

find_real_file.png

 

If you have some example code, it would be great.