Creator Toolbox - Quebec Script Tracer
[Music] hello and welcome to creator toolbox this is the webinar that lets you learn more about servicenow developer stuff regardless of what your skill set is on servicenow i am so excited to be here but let's do our introductions first we have andrew barnes who's going to be showing us something very exciting today hi andrew happy day chuck i'm andrew barnes developer advocate here at servicenow i am uh you know just uh just pleased to be here today i have been working on the platform for coming up on seven years um knowledge 14 was my first servicenow event uh and we're about to to come up on knowledge 2021 which is exciting um and i i've got nothing else to say i'm just excited to be here it is a beautiful day and i found out today that i am as of noon i can register for my kovid shot they're opening it up to the uh 55 and older crowd now you're not a day older than 28 yeah yeah keep lying to yourself it might be true my name is chuck tomasi senior old man and uh i've been at servicenow since mid-2010 i was a customer for a couple of years before that and uh like andrew i'm just happy to be here what have you got for us andrew oh i'm so excited today uh to show you my favorite quebec feature so quebec is our current uh early access release version of servicenow we're about to leave early access and go to general availability and for developers there is nothing more exciting to me than script tracer so typically uh you know we're doing live coding on uh most of our broadcasts here and unfortunately i can't do uh like i can't accidentally force a place where we need to do error checking and debugging so i have put together a scenario today that is a real scenario but has been recreated for this and i'm going to walk you through how i went about debugging this before uh quebec and using the platform capabilities that allow me to debug things and then highlight how i would do it starting now in quebec which will show off script tracer so that's what we're going to go through today um do you have any questions before we dive in we had some good ways to do this before yeah and you'll show some of those and and now we've got an even better way this is really helpful who who's the who's the primary persona let's start with that that that uh yeah the primary persona here is your you know more expert servicenow developer who's doing uh you know diving in and doing scripting um and trying to understand why um you know what's going on during a transaction um you know so i'll walk through the scenario today which is i'll be working on a business rule and i'll have an unexpected behavior that's being caused by something that's not my business rule and i don't know what's causing that and so that is a good example of the time where you'll you'll need to to use something like script tracer or any of our debugging tools uh to figure out why an unexpected behavior is being caused and then go look at that and address it potentially with other developers i love how you know it's going to break now typically you don't in the real world like surprise this field is whacked and you know some downstream stuff happened and surprise so yeah by the time you get to script tracer you're usually aware of something is happening and uh because it can be a pretty deep stack i don't know if you've ever turned on like debug business rules you just do a save on an incident it's like holy smokes there's a lot of stuff that's right for days it is and and you know some has skipped and some as you i mean very useful information you'll show us some of that i hope actually this is this is one step better because now you can start well i don't want to take away the thunder let's save the thunder all right so uh let's dive in i will start by sharing my screen with you fine folks watching out there in youtube and twitch land today um so i am a servicenow developer um i am working on this business rule to solve a you know requirement that has come in i'm working in my update set in the right scope and i have this business rule on incident and uh you know sneakily enough just called showcase script tracer because that's what we're doing i told you this is a little bit contrived of a scenario uh because forcing a bug is uh you know not something that's easy to do on a live stream and it's not natural it's hard to break your own code yeah it is um so we on the incident table we've got this business rule that's going to run i've got it light on conditions right now so i'll make sure i invoke it but basically it says if i've got a problem record then i'm going to do this very simple script which is to set a value of contact type over in my problem record from the value of subcategory on incident and and this works so let's show it working so uh over here i am on this incident record and if i change uh you know subcategory here to operating system and then hit save i've got this related problem already um and you'll see that uh i have already let me let me reload this kudos to jason in the chat he says i break my own code all the time i think we all do we all do it's just not something you want to do on purpose so i'm going to save this record and see subcategory was operating system and over here we get set operating system and you'll notice what i changed was my normal tester is is fred luddy our our founder fred luddy here uh is is my favorite tester and i was testing with him and you'll notice that the subcategory or the contact type was set over here um and you'll see what happens so i've got operating system here i hit save and my subcategory changed on me well that ain't right because you didn't change the subcategory you were changing the contact type on the related problem record right but that's not a normal thing you shouldn't see okay you shouldn't right yeah i agree um and so my code did what i told it to do which was copy that over and and so my business rule is working but someone else's business logic when the caller set fred bloody or maybe some other conditions on here it's setting the subcategory to one um and one isn't a valid option for that field so we've got a problem yeah i would say so i think i think you've got two problems one is that it's setting subcategory and then you know it's being amplified by your business rule that's copying it to another record which is a perfectly legit use case this happens all the time all the time um so what are the options for me as a user here so i've got a few of them right so if i go back to my business rule i've actually set one of them already which is or started to so over here in the uh you know script number gutter area i i don't like that name but it's the name it's the name i call it the edge but gutter is probably more appropriate um that's what our docs call it so that's what i call it um so i can set a log point so i can you know do something like log what the value of the subcategory is when my script is running and this is different than putting a gs info right into the code it is and and what's the do you know what the difference is one is going to be in there all the time it's part of your code and it's going to run every time it runs and when it gets to prod it's going to run a log point is hey i'm doing this as sort of a band-aid approach it's a temporary log statement absolutely and it only runs during my session so if you log out and come back all your log points are gone well and i'm not affecting other users either well that's true you're not polluting the law i'm not assisting other developers or even if i'm using a log point in production i'm not affecting other users i'm just affecting my user okay a gory look at me i'm i'm typing a thing out chuck i don't normally do that where's the copy pasta where's the coffee pasta i almost did cause i almost spelled subcategory wrong all right so i'm gonna log that but unfortunately i already know that that's not going to help me and the reason i know that that's not going to help me is because my script picked up the new value and copied it over right right so um i already know that when my script is getting there um subcategories already set the damage is done the damage is done yours is running after because you're changing a record related to your current incident absolutely since i'm not modifying the current record i'm running this after i could even run this async i'm running it after so i can invoke it easily from debugging because async doesn't uh debug quite as easily yeah and would it be safe to assume that the possible culprit is in a before business rule it it very well may be it could be a before business rule it could be a flow it could be a workflow it could be any number of things that are causing this but in order to start debugging that i am going to fire open my trusty script debugger window because i've set a break point and i love break points so break points and log points act as break points is that the so i set both a log point and a break point oh okay okay and i can see both of those here so on line four i've got a log point and on line five i've got a break point and so if i go invoke this uh logic again so i change the record and hit save over here i will stop my execution at the point that my code was run and i can inspect it and if the thing that i need to inspect is after where i set my break point then i can actually step forward in time and find that that business logic that caused my problem unfortunately uh for us uh we can see that our current record and the subcategory value at this point is is too late for us it's already been set and we can't go backwards in time with the break point we can only step forward so i can move forward in time and you know step forward and step forward and see the the future business logic that's applying on in my transaction so this is a really powerful tool when you know early enough where to start looking but if you're after a thing has happened it it is uh it's too late so you have to find a place to put a break point early enough that you can step forward so i'm going to resume my transaction because now my log point and my break point have told me the same thing which is that subcategory is set before my after business rule yeah yeah so uh one thing you mentioned that you can do is over here in the session logger you can go to settings and then you can turn on the business rule debugging now that's handy i then i've i'm still an old school person and go to system debug or system diagnostics find the right one turn it on nothing really appears to happen this is handy because it's going to be logging back to the session log anyway it comes here i mean it also goes on the standard forms and lists below so if you wanted to use your browser to find it but i just find that session log window is so much easier to use so let me resume that and then over here what we'll get is this is what appears at the bottom of your form but here in this window it is filterable and searchable oh so i could go through this and inspect all of the different business rules uh search for sub-category or whatever in search for subcategory and things like that so i could do that category okay what's this one subcategory something changed yeah but hmm something changed it something changed it okay we know something helpful i already knew that [Laughter] i told you we had good tools before now we've got something better so so this is one you know another way that i can do it and then the uh the last thing that i will do uh before i move on to the script tracer is let me show you what what i most commonly would have done uh as actually one of the first things sure which is i hope go to the business rule table um for uh so actually we do it from here i go to configure business rules on my incident record yeah this is common if you if you've taken over someone else's project or you don't remember what you worked on six months or six days ago and you have a brain fart and you say well it must be in here right so you went and checked the business rules for what script contains subcategory uh so the first thing i do is just see if anything was modified recently and the answer is and the answer is no um and then i would do something like what you said which is you know script contains uh like sub category yeah and nothing except for yours that you know which which i just called right you know yeah this is not my culprit because i created it so uh let's turn off the the business rule debugging and let's turn off our break point so that we don't get interrupted that you know that's another advantage of that uh session log window when you do this from the module together well not that they're all together but if you turned on say business rules and sql but you just wanted to turn off the sql queries you can't do that from a navigation yeah that because that module just says turn them turn it on and it's and then it's disable all like oh wow so that lets you be a little more prescriptive in what you're turning on and off and go just now um so let us now go show off script tracer so that's what we came here for the third tab here is our script tracer and so i've got a new record queued up here and i'm gonna make a change and we're gonna you know set it to fred come on you can set it to fred all right so now i'm ready to perform my action so i'm going to say start tracer and this is going to start inspecting again this is like break points it is just affecting your session in your transaction so it's not it's not having negative performance on the system for any other users it's just my user so i'm gonna hit save and we get uh some information here so i'm going to hit stop trace okay and start looking at uh what happened so the first thing that happened was the save button which is i pressed the save button and it said hey you press the save button and the save button did some stuff and in this window you can see that the short description is highlighted here and what is changed in the short description i can uncheck this which uh you know says you know filter down to just the things that were changed and see all of the values and we can see short description was changed here we may want to sort that at some point but i can you know filter it down to just the things that changed and i can even inspect the script from that ui action i can open up that script but but this isn't what caused my problem so i need to move on to the next thing now there are some filtering capabilities here we only have three records but there'll be many times especially on task tables with slas that you're going to get a lot of information here and you're going to want to filter it down so let me just show you that there are filter capabilities so the table affected because it's not just inspecting my incident table it's inspecting any record that is touched as a result of my transaction so that's what this is doing um and we see that we changed incident and problem in that transaction good to know and i can filter that out then the uh you know the engine that caused the the change so script includes business rules flows etc are going to be here and filterable and then you can do text filters we don't need those because we've already been narrowed down to three things we can inspect three pretty easy to go through those so i click on the second one and i get subcategory changes from ip address to one on my incident table this feels like the offender it does feel like the offender the question next question is so this has told me exactly what yeah what has caused my problem is uh i i know that the result was subcategory changed to one and i didn't want it to and this is telling me this is the thing that caused some category to to go to one so i have found the culprit um and i can nice i you know i've got a little inspector here that shows me where in this script this has been caused kind of okay i can go inspect this script oh sorry hit show script and that will open up the entire full script yep that'll retrieve the whole thing especially in long ones this is really powerful i could open up the file itself so this will open up the uh this script include in its own window so this is showing me that hey something has called this script includes that's what i was saying it kind of tells you but it doesn't kind of tell me we need to know who the who's invoking this so we have a way to do that too right we do have a way to do that what's your what's your two-click method to find the baddie uh click view file yeah that's gonna open the script include in the regular full editor for me and then i can right click on the script include name and say find references and you'll see that itself references it and then this other set incident in active business rule hmm all right hold it right to go let's go okay why why was that not shown as one of the things in script tracer yeah that's a good question um so and the answer lies in that that business rule didn't actually cause the change directly so script tracer here when i click on one of these you will always get um in this state uh area what changed and which thing caused that directly so it's looking for basically set values that are happening yes okay so so though it it went through that business rule that's calling this script include the script include is actually what did the changing of the value and so um i could see a future enhancement where it could tell me what invoked this script include but but right now the way it's constituted is this shows me what caused the thing directly okay and we're just a couple of clicks away from getting to that anyway so yep and so we'll see um that uh this business rule um is got a property it's buried in a property oh that's always fun to find it's not just it's not just the script include or the business rule is doing something nasty they and you'll see that this is supposed to set incidents inactive and somehow this property for which field to change has gotten changed from uh the active field to the subcategory field and so i can go open up that property and change it and and or well more importantly i can go talk to the developer that calls that and see why that happened and if it's appropriate to revert that has this ever happened to you someone changes the property and suddenly the whole app goes off the rails but yeah so i can copy this uh you know and go over here and do open that and you'll see that this is set to subcategory so now i now i know why this is happening and then i can start to address it either through logic or to through talking to that other developer so script tracer allowed me to figure out earlier than my my business role what was causing issues before it um whereas uh that's a big enhancement to me it would have saved me weeks of development debugging time in the past and i'm just i'm so excited about this i think it you know it's gonna be super valuable out uh to any developer uh to figure out what is causing their uh you know the values to change and what was actually touched along the way this is um you know so break uh breakpoints and the script debugger are awesome from everything forward of your point of uh breakpoint um but this allows me to figure out where to set my break point early enough and filter it to just the right things that i i should inspect uh so it allows me to go faster and i like going faster what's under the transaction tab we didn't look there yet yeah so this is similar to what you get on that left-hand side of the script uh debugger window during the breakpoint so this uh equates to in the script debugger over here this this panel so the transaction details gotcha and jeff in the chat says i don't see an option to enter a log point in the business rule script how is that done so most likely you need to go set a system property so if we uh you know return to the system property list and not oh that was bad let's just go to this properties um what's it called a log point nope you have to spell it right um log underscore point i don't remember the name but i know i've updated it recently it's glide.debug.log underscore point there you go easy enough so turn that on and you can set your log points if it's not so yeah if that's set to true uh you'll get that option in your business rule uh to right click in that uh script uh box gutter for log points and the proverbial question about does this come with quebec is it a pay for product all that stuff what do you think it is natively in quebec um there's no plugins need to be activated or anything and there's uh this is a core platform uh capability so there there's no i can rarely say this but there are no licensing implications with using uh script tracer very nice very nice just looking around and see what else in the scriptchaser uh that you want to inspect i think we covered uh pretty much all the the details um the filtering will be really useful uh when you have you know 50 things um but oh definitely this one it was it was it was already narrowed down to us pretty good yeah and i've seen it where it is 40 or 50 things and half of them or more are say task sla i'm like you know it's probably not that so let's just filter those out and you get down to something that's more manageable and like we did we could either step through these one by one i go where's subcategory where subcategory where subcategory or you can do a quick search for it so uh uh available from orlando yes log points are available starting in orlando so they've been out for about a year sounds about right i know it's you know since since roughly that time maybe one one family before that uh log points came out the family uh version after break points any announcements we need to make okay any announcements before we uh are we done screen sharing i should so let's stop the screen share okay and that was fun i'm so excited about script tracer yeah thanks for uh you know going on that journey with me i know it was a little bit of a contrived scenario just because invoking an error on demand is not the easiest thing to do but i hope this was valuable and showed uh you know the power of the script tracer and just hopefully shows you how i go about doing debugging in general and and some of the tools that are available because you know if you're not doing it regularly you can easily forget about things like uh turning on debugging uh acls or uh you know using log points um you know because if they're not high you know in your thought process it's easy to revert back to a thing you did five years ago or uh you know that's that's not as familiar yet to you gives me an idea for a video series debugging only i had 30 more hours in the week we we'll we'll order you up uh some extra hours so you can do that um so i think that was a fun uh that was fun i hope uh you out there uh who are watching this uh found this useful um we'll also have uh a uh i think i already have a blog on script tracer but if i don't i will and uh feel free to add comments to that or to this youtube video uh if you're watching this in the future there's a there's a blog on script tracer coming out thursday of this week so march 4th there we go we've got it all scheduled up and ready to go do you have any i think you have a break point coming out tomorrow don't we have a break point episode coming out tomorrow with one of our product managers charnlin he's going to be talking about the command line interface and i jokingly said wait a minute churn lin and command line does cli have anything to do with your name you thought that was funny you didn't expect that question but uh yeah breakpoint you can find that at bitlybit.ly sn breakdashpoint and then subscribe with or if you want to find it on apple me apple podcast or google or amazon spotify it's all over the place so yeah i look forward to that and thank you everybody who has listened and subscribed to that we just had a tech now episode last week which is now on the community and on the developer blog and on youtube so wherever you find your tech now episodes episode 84 with jeremy duncan we walked through configuring the workspace a lot of great questions in there very popular topic as we get more into the now experience and workspaces and components we're putting together a whole collection of good information for that uh what else have we got coming up more quebec we're winding down on early access for quebec uh so soon it will be general availability and we might even uh you know have something extra in store for that period we've we've actually got to the point where the product managers are asking to be on our shows and we're now we're we have to un untie that ball of yarn figure out exactly how we're going to do that effectively for you the viewer so that you get that information and uh you know it's timely but it's also you know appropriate and and well thought out so uh not that our product managers are not well thought out didn't mean that to come off the wrong way these are very smart very talented people well thank you so much uh everyone watching and uh thank you chuck for riding along with me and definitely can you close this out sir close us out thank you for joining and everybody stay safe be safe and we'll play that little jingle that we just borrowed you
https://www.youtube.com/watch?v=qWxJbJvDMuE