Manipulating the "Post" button

niagarwal
Kilo Guru

Hi Community ,

 

Is there anybody who has tackled a requirement of enabling a confirmation pop-up once the Post Button is clicked with/without DOM manipulations ?

I am able to get to a point where on click of the Post button , the confirmation box appears.

However, an OK or CANCEL still inserts a record into the additional comments.

 

find_real_file.png

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Can you share the script which is allowing you to open confirm box when post button is clicked

Also what code is written when CANCEL is clicked?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

niagarwal
Kilo Guru

Hi Ankur,


Here is the outlined code... Not complete in entirety though

 

function onLoad() {

                window.setTimeout(addPostListener,2000);

}

function addPostListener(){

               

                var PostButton = document.getElementsByClassName('activity-submit')[0];

                PostButton.addEventListener("click", myFunction) ;

               

                function myFunction() {

                                   if (confirm('You have entered Additional comments. Are you sure you wanted to do this?')){

                                                //return true ;

                                }else

                                {

                                                //alert("Not Confirmed");

                                                //return false;

                                               

                                }

                               

                }

               

}

Hi,

can you try updating code as below and test once

function onLoad() {

window.setTimeout(addPostListener,2000);

}

function addPostListener(){



var PostButton = document.getElementsByClassName('activity-submit')[0];

PostButton.addEventListener("click", myFunction) ;



function myFunction() {
var retVal = confirm("You have entered Additional comments. Are you sure you wanted to do this?");
if( retVal == true ) {

// OK clicked

}  
else{
// CANCEL clicked
return false;
}

}


}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi Ankur - Unfortunately declaring a variable and then checking for it , does not work either.