logo

NJP

ServiceNow UI action confirmation | ServiceNow Usecase Confirmation pop- up on destructive UI action

Import · Mar 11, 2022 · video

[Music] hi all and welcome back so a new video and new use case you can say okay so in today's tutorial we will be looking on one more use case so considering scenario uh you have created one destructive action means you know with that particularly using that ui action you will be performing certain activity and which can't be rolled back for example cancellation of change cancellation of something or closure of certain things out and what you want to do keep as soon as you click on that incident there is a chance that it can happen by mistake and also okay so you want to take a confirmation from the user before means performing that action right so in today's tutorial we will try will be creating a cancel incident you action okay and what we'll be doing on top of that reaction keep when a person clicks on that you action it asks for confirmation from that user whether he really wants to cancel that particular record or particular incident or not if so that it would be like two factor authentication before closure or cancelling of certain things this use this is a generic q skill but you can uh extend the extend of functionality to your own needs okay in your own projects so let's get started so as always we'll be using incident table our favorite table for for the demo purpose so let's go to the instagram so instagram.list and let's open the instagram in the new button new state so for example if you want to cancel the incident from the new state right so where exactly it went okay i will open it again to taking some time now till the time i will duplicate the record so that we can go to action okay so what functionality we want to create a new action on the incident form called cancellation of probably okay which will cancel the incident pretty straightforward i right click i will go to configure i will go to you actions okay i will be creating a new action now i go to new i'll give it a name called cancel i will give it an action name as can still underscore incident activity i want it as a form button form style it's a destructive so i will give it a destructive one client definitely on client any other thing no no on click what we will be doing i on click i will create a function which function i will be can incident let's define a function cancel incident cancel let's say that right we will go to condition condition let's let's put a condition i want it to be visible only on new state so what condition i can give i will go to the state choices choices so we'll look for cancel of the cancel s4 okay sorry i haven't had i'll keep on playing around this i don't know what the current value so new is one and cancel is eight perfect so you'll follow this something let's go back and we'll give current dot t equal to equal to equal to 1 is one only right yeah now this is done we will save it out and see if the button is visible or not we should always go in a step-by-step manner rather than creating everything and then just trying to why exactly it's not working and all the stupid things right so we will reload the form to see a button oh wow it looks pretty right cancelling it if a person is that polish that after seeing that it's the district you read okay alert then also if we do mistake we should avoid those mistakes also so now our button is visible now what we can we have to do we have to define a function called cancel incident so let's do that so we'll do i will just expand it out somewhat it will be so i will give function function cancel incident and we will give a confirmation box in that so we will give a variable answer equal to confirm right confirm and i can give are you sure you wanna cancel this this incident question mark question exclamation expression and okay now what will be doing if on so answer if answer if answer is true then what we'll be doing gs ft submit you should not forget this you can submit and in that bot first parameter i will give here null second one i will get here this code dot get form element pro set okay let's go form element and the third attribute we have to give it action name what's happening with my keyboard let's first give this and then i can keep this and then i can what is the form action name i will go over here with the formation first i think cancelled in a second let's go back give it up cancel incident right if advance is true then we will execute a function called cancel incident when it says you action again on the server side else we will not do anything so i will false right now we will define our server set code okay ensure you always called server set code with no browser errors also okay so we will do if type of type of window equal to equal to undefined if we don't know the window type then what we'll be doing is simply call server close function so [Music] it's not closed will you cancel it server cancel now what this particular server cancel will do i will give you a semicolon so i can't see that warning now we will define a function so cancer so in this what we'll be doing current dot state equal to what is that eight right date and then we will simply go to current want current instance update i think it should work fine let's verify it once so basically what we are doing as soon as the button is clicked we are just giving a confirm box okay like are you sure you want to capture the asian city if they give yes then we again execute the server set code if they say no then okay fine we know it's mr can happen so we'll not do anything and we'll stay on the form if it's yes that means if it's true then what we are doing we are calling a function called server cancel okay and in service cancel what will be doing state will be changing it to eight pretty straightforward right let's save it out and let's refresh the form why to refresh the form because we have client set components also in our script so now a person came here by mistakenly click on this cancel and it gave a message are you sure you want to cancel an answer this isn't it no i don't want to cancel this internet fine so we will not do anything if you again come and if you you click on this one are you sure you want to cancel this which is incident it happened by mistake again no no i want to cancel this incident and as soon as you click on the cancel ah it redirected boom it can set that particular incident out pretty easy right so you can use this logic whenever you are creating some destructive function your actions okay so basically whenever whenever you are creating some destructive action so you should violate it from the user you should take confirmation from the user that do we really want to do that okay if it says yes then yeah you can you can you can go ahead right so this is all for today's use case okay hope you find it useful and you start implementing your destructive buttons like this okay please like follow subscribe to my channel to get this kind of videos in the future also till then stay safe stay happy and have a nice day thank you you

View original source

https://www.youtube.com/watch?v=8ZfGDSxHXNs