Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Close spModal after 10 seconds

ashfaq
Tera Contributor

I am looking for a piece of code to delay the closure of the spModal box. Currently as soon as you click "OK" the box closes however, instead of this I am hoping there is a piece of code I can use on the client script that will delay the closure of this box once the OK button is clicked by 5 seconds. This is for the portal. I currently have the following code and I would like the box closing after the it has been updated on the server if that makes sense as there is a slight delay in the background therefore, I wanted to box closing once the background work has been done. So I would need to add some code after the server update I think. 

function(spModal) {
/* widget controller */
var c = this;
c.amendAuthorisedManager = function(value){
var warn = '<i class="fa fa-warning" aria-hidden="true"></i>';
if (value == true){
spModal.open({
size: 'sm',
title: 'Add as Authorised Manager',
message: warn + ' This will enable the user to request access to company owned data and systems on behalf of other users.<p>Are you sure you want to make the user an Authorised Manager?</p>'
}).then(function(confirmed) {
console.log('widget dismissed');
c.data.amendAuthorisedManager = 'Add';
c.server.update();

 

6 REPLIES 6

asifnoor
Kilo Patron

You can add delay like this inside then function

setTimeout(function(){ 
  c.data.amendAuthorisedManager = 'Add';
  c.server.update();
}, 5000);

Mark the comment as a correct answer and helpful if it helps.

ashfaq
Tera Contributor

find_real_file.png

I've added that but not sure if I have done it right and it's not working unfortunately. 

ashfaq
Tera Contributor

I just want the OK box delaying as soon as you click ok

I hope you closed the braces correctly for then function as i see it missing.

I think the box closes immediately bcoz thats a default function for which we will not have control. Anything to happen after you click okay can be delayed using that function.