logo

NJP

#5 OnCellEdit Client Script in ServiceNow | Client Scripts in ServiceNow

Import · Dec 14, 2020 · video

[Music] please subscribe to my channel and click on the bell icon to get the regular updates of my channel and do not forget to like comment and share hello everyone welcome back to sas with servicenow this is part of short series of learning client scripts in servicenow in this video you will learn about onsell edit client scripts in service now what is on cell edit client script onsell edit client script runs when user change value on a field in a list it is used when you want to perform some action on the client when field value changes in a list view you need to select type as on cell edit to create onsell edit client script and you also need to select field name that is the field on change of which you want some action to be performed on the list now once you will select on cell edit type you will see the function on cell edit automatically populated in script field in which you can write your script to perform any action in the list view you can also provide parameters for onsell edit client script this is similar to on change client script now you can use these parameters in your script as per the use case as per the requirement you get from your customers and clients and the parameters we have sys ids it's an array of societies for the all items being edited in that list view then table that for what table of items you are basically editing then we have old values this stores the old value of the field which was populated before the change and then we have a new value which stores the new value of the field which was changed by the user then we have callback parameter now callback can be made as true if you want to continue the execution of any other related cell edit client script major use cases of onsell edit client script starting with stop user for changing short description from list view so if you want to stop user from changing the short description in list view that you can achieve with the help of onsell edit client script then we have field values calculation on change of fields in list view if you want to do some calculation when user is updating some of the fields in list view that you can achieve with the help of onsell edit client script and then validating dates before saving the data in the list view so before users save that record while editing list view in that case you can use on sell edit client script to validate the dates or any other validations as well let me show you some practical examples of onsell edit client script scenario 1 when short description is changed in list view then system should populate the confirm box before applying so if i go to my personal developer instance i will go to client script and here you can see all other client scripts are inactive and i will click on new and here i will just confirm short description change table i can select incident quickly and i will select type as on cell added as soon as i select on cell edit you will see this new function over here and here i will select shot description that's our requirement in the use case we have then what i will do i will just make it maybe full screen and i will zoom it and now i will write the script now you can see this save and close so basically here call back we are returning true so basically we are sending true parameter to this callback function now in this case this will execute other other onsell edit client scripts as well however if you do not want to run then you will return false so in this case i will start with uh when when user is changing the short description then there should be a pop-up a confirmation box where user has to provide input so what i will do i will also capture that input that's how i can confirm whether i have to save the racket or not so in that case i will do where you input i will do you input and here i will do confirm and i will put are you sure to update short description now i can just start with the condition so i have to check what kind of input i have got from the user so if user is clicking on ok so i will do u input equal to equal to true so i'm getting true from the user when user clicks on ok button so in that case i will change the value of save and close and that would be true so i will keep as it is as is like we already have save button true so i will keep it true now if it is not true that means the user input is not true it is false so in that case i will do save and close as false so then it will get false and it will not take any action so i will save this client script so this will create this client script and now i will perform testing how exactly i can perform the testing so i have to open incident list so for that i will just quickly go to the module i have for incident let's say this one i will open in a new tab now here we have this short description so let's uh maybe change any other short description so i will change this one i have double clicked on this and now it will basically give me opportunity to change this shot description and if i am let's say i'm removing this value and if i will click this icon this green icon it will basically show me this confirmation box are you sure to update short description if i will cancel this this will not take any action but if i double click on this and this time i will remove completely i will just keep employee over here and i will click on save and if i click on ok this time this will save the racket so i will click on this you can see it has saved the racket so that's how it it is basically taking the input from the user and saving the racket overall if i go to my client script quickly and just explain you how exactly it is working so the important piece the important line of code if i would talk about it is this one so whatever value so if you're performing some changes and if you're performing some validations if you do not want to save that racket when user clicks on that green icon then you have to basically return this false so save and close value basically this callback function should get the parameter as false value and if you really want to save this record then it should get true and if this callback function will get true parameter then it will save the racket it will also run some other scripts as well but if you do not want to run if you do not want to execute any other scripts in that case you can just return false you can just basically uh save the value assign the value to the save and close variable as false in that case its form will not be able to uh that the list view the system will not save that racket any any uh anyhow that user will not be able to save that racket so this is how you can create on cell edit client script in service now so thanks for watching this video and have a great day

View original source

https://www.youtube.com/watch?v=kYq8vAX4-SY