logo

NJP

Test Client-Side Code with the JavaScriptExecutor | ServiceNow Tips & Tricks

Import · Jan 19, 2023 · video

welcome back to the second part of my two-part video of sharing tips and tricks for service and developers and the second tip that i want to share with you guys today is called javascript executor as a developer this one is quite possibly my favorite feature in service now so we are all familiar with the script background module as well as those beta feature fixed scripts which is used to test server side skips but if you worked on client side code you know testing a simple glide from message or testing like like ajax called isn't straightforward but today you are enough because service app has a feature called javascript executed in the default system all you have to do is press ctrl alt shift plus j for all the window users and control option plus shift plus j for on the max user on your keyboard to open up the javascript executive here you can enter any code in an unformatted structure similar to how you do it for background script and execute it against current view of the system and as a bonus if you change the option on the bottom left from actually execute my code to browse layers you can view a list of all available browser environment variables on the current form and review the set type and value of those variables this is quite useful for testing changes on the client side before making updates for application files on the system back-end so without further ado let me go to the system i'm going to navigate to one of my test catalog items go to maintain items and then wait for it to load click on my test item here to open up my catalog item in which i have created a single line text variable called max duration and once i have this i'm going to click on try as you can see this is my single line texturation and i actually want to do some validation on it when i want to check the value within a certain range so all i'm going to do is press ctrl option shift j it's gonna open my javascript executor as you can see i'm gonna paste in or write in my code so in here i'm declaring a max duration variable which is gonna get the value from this form variable convert it into an integer to a validation to check its values less than five and if it's greater than certain days which is 13 to 24 into 60 and if it's go then it's going to show a field message of type error so let's start so i'm just going to replace the video here with the value which is 3 which is less than 5 so i should be seeing an error now perfect so as you can see as soon as i clicked on run my code the max duration i see a message that says max duration must be between five and these seconds which is 30 days and the other feature that i was talking about if you click on browse where's you can see all the different attributes here variables of the browsers that are available with the name of and type as well as the value that's available so this is again quite a handful feature if you want to look at the base uri this is the uri that you can get of the browser that you're looking for so perfect now that was everything for me today guys thank you and happy coding [Music] you

View original source

https://www.youtube.com/watch?v=Xsz5flLy8Ns