Community Live Stream - API Adventures - GlideAjax
foreign you you you [Music] hmm [Music] [Music] [Music] [Music] [Music] [Music] so [Music] [Music] [Music] [Music] [Music] now [Music] [Music] [Music] do [Music] [Music] [Music] [Music] [Music] [Music] [Music] [Music] [Music] [Music] [Music] good morning good afternoon good evening wherever you are and whenever you are welcome to the community live stream my name is chuck tomasi from servicenow senior developer advocate this is november 30th 2020 and our topic today is glide ajax always a classic always a favorite and asked frequently on the community so i thought it's time to put a stake in this thing i'm greeting the chat this morning thank you very much for joining if you're watching this live on youtube appreciate it very much we do have a very wonderful live chat going on number of people recognizable faces returning in new faces showing up it is all times of day and night as we do this live 2 p.m utc on mondays and thursdays hope to see you there i did uh have to laugh at uh at myself for misinterpreting one of the names the the i believe the handle is grown ups but i'm so much of a nerd i read that as grown ups as an uninterruptible power supply not the package carrier okay that's just off the edge that's what i read this morning why would somebody be a grown ups what's a little ups look like if you've had fun with data centers and uninterruptable power supplies you'll laugh okay that's that's all the humor you get to well no it's not we're also going to do this on twitch at the same time as a backup plan and as a backup to the backup we've got a local mp4 being copied i will warn you that i have had some internet issues the last couple of days working through them not sure they're entirely resolved speed tests in the last few minutes have shown you know we're we're getting what we expect and sufficient enough to hold up this stream but if something happens and the stream goes weird i will upload a nice clean locally recorded version i won't have the interaction from the chat but we'll get through this and i want to make sure you get this glide ajax information right away okay you know once those of you who have children know about seeing things in a different way that's what happens when you have kids a long time ago in a galaxy far far away that my kids distorted my view of the world and now i see things like grown ups that's what they will do and now they're married and going off to jobs on their own oh where does the time go well i can tell you where my time goes it goes a lot into making these videos for the community and i invite you to spend some time in the community as well either reviewing questions dig into something you don't know and learn about that get involved with that thread or discussion or completely new forum or post your questions out there there are hundreds of thousands of people that are willing to help you out so over at community.servicenow.com especially if you're watching live and your question goes outside the purview of glide ajax it's a wonderful topic but if you start asking me questions about secops or grc or incident management it's not happening here that goes in the community that's what you see behind me i invite you to partake of that also invite you to go over to developer.servicenow.com where you can get a free personal developer instance and i can try and find my cursor on here okay i've got to get the next screen set up it all happens live one man show lights camera action video angles buttons music it's all me it's amazing anything happens murphy's law is just waiting for a sniper attack today to make sure something doesn't work i gotta check if the mic is unmuted anyway developer portal free a free developer instance that's a wonderful thing use it as your sandbox test it out free apis free learning plans blogs videos you name it we're we're coming at you with more developer content every day if you want to make that career transition from admin to developer this is a great place to start if you're new if you've been doing development for 10 15 20 years on other platforms and you want to learn about the now platform and how things work this is a great place to get started and if you want to discuss face to face with some of these people well virtually face to face right now but eventually we'll get back to real in-person meetups meetup.com pro see if i can say this this morning it is early but i can talk most of the time meetup.com pro servicenow dev program is where you want to go and there are meetups happening all over the place i believe what is it vancouver somebody's got one coming up next week there's a couple this week you know why don't i just scroll down because that's where the info is we've got uh pune is december 19th we've got vancouver on the 8th i will be attending that one looking forward to that very much if you're if something is in your time zone or slightly out of your time zone i invite you go check them out they're happening virtual it's really easy to attend without too much imposition on your schedule the 15th we've got stockholm the 19th we've got mumbai dc on the 10th everybody's getting their pre-holiday ones so wear your party gear your ugly sweaters turn on the flashing lights do what you would do let's make it a christmas party at every one of these how's that for a goal have fun good morning to everybody who's joining me live on the live stream yet community live stream we're going to go talk about glide ajax today so thanks chat uh no michael it is not 6am in arizona cause arizona doesn't change their clocks it's 7am and it will always be 7 am because i don't change my clocks that's why you guys got to do the math on this one i say 2 p.m utc for a reason there's some thought behind that phrase all right i also want to remind you that there is a developer podcast it's been out for what about four almost five months now wow where does the time go break point is what you want to look for when you go searching through apple podcasts and google podcast or spotify or amazon or wherever you get your podcast breakpoint is the developer podcast we had a wonderful discussion last week with tim woodruff if you haven't heard that i invite you to listen you can watch you can listen online it's audio only i shouldn't say watch you can listen online uh there's no updates that's no powerpoints no demos it's just open discussion between external developers internal developers we've got more stuff planned the pipeline is full very much looking forward to do doing more break point episodes in fact i've got to edit up our next episode which will be coming out on the what would it be tomorrow's the 1st 2nd the 9th december 9th i'll be releasing an episode with josh nerius all around integration hub and some of his favorite features and you'll get a sneak peek into the road map of what's coming in integration hub in quebec and beyond so looking forward to that very very much got to scroll down make sure i didn't miss anything in the notes nope right where i want to be so go listen to breakpoint also if you haven't done already go over to bitly tn 82 reg sign up for our next tech now which is on december 15th for instance data replication or idr easiest way i know to move data between two servicenow instances takes care of all the security very easy to configure very fast i'm gonna let craig step tell you all about it and demo it so look for that coming up in just a couple of weeks oh my gosh ugh this machine needs to keep being fed we will be doing a little bit of scripting today and i will make sure that i have all of those scripts available for you over on the github repo that you find at bitly sn-cls that's the shortcut the real name is too long to you know takes too much time but i make these links short so you can remember them i can remember them we can all type them in easily you'll find a dated folder with today's date 2020-11-30 with a couple of scripts i'll be walking through some client scripts some script includes test script i'll make this all available moments after i hit the stop button on the live stream so you can follow along there grab these scripts try them on your personal developer instance and get going that way if you are not familiar with javascript and some of the stuff that i'm going to show you today looks like hieroglyphics you go what does that mean i invite you to jump in and start learning i take you from the basic of basics variables and statements and we will build up slowly and surely and in no time you will be able to recognize modify and perhaps even create some of your own javascript on the now platform so i invite you to look at that thank you thank you thank you to everybody who has participated in that and recommended it that's even more important if you've got colleagues that would like to learn more you've got admins who want to become developers you've got people from other platforms who want to jump on the now platform and start doing this javascript is a great place to start so hopefully in the next few days you'll start seeing some of my integration series coming out too so we'll get that taken care of in the meantime let's take care of what we came here to do i'm going to go over to my personal developer instance and our use case today is going to be around gladiatrex as i said i've got two fields dependent fields on a form and i want to do the same kind of thing in a record producer now dependent fields don't exist in our record producers and you may have a different use case where you need the client side i should back up and explain what glide ajax actually does okay we've got a client script and we've got a server side component because servicenow can do scripting on both sides most people who are new to the servicenow platform are aware of client-side scripts but there's a lot of power in the server components like accessing the database directly well every once in a while you need the client to have data from the server it's not all we're not passing you know every record for every it it wouldn't make sense it would slow down the whole experience too much and so every once in a while this the client has to say hey i need some data that i don't have it can do this in one of a couple of ways one is if the server pushes that information through a mechanism called g underscore scratch pad you can put that into a business rule send it over the client script has it but it's static once it's sent it's sent and that's what the client has if it's something like a system property perfect you don't need to go every client script saying hey i need that system property and i need that system it's not changing all that much really because system property shouldn't but you can use g scratch pad to say get the we'll do that in a little we'll talk about g scratch pad a little more detail in the future but it can push that information the other option is to have the client request this now underlying a lot of that technology is what they call uh xml hd http xml you know i can't remember because it's so far down i don't even care anymore but there is a request that happens from the browser to the server that says i would like some information the server acknowledges it does the transformation sends it back either synchronously making the client wait so synchronous and asynchronous important that you remember the difference between these two because we will be getting to these in just a little bit asynchronously means happens in the background okay the client makes a request and while the server is processing and this could take a few seconds you don't want the browser to wait a few seconds i'm sure you've all experienced something where you're waiting and waiting and waiting and going boy this system is slow well not necessarily it may be doing something downstream like hey server go get me this data and the server says oh i have to get that from a third party does the arrest request comes back meanwhile the client is sitting there locked up waiting you can do that asynchronously so that the client can go on and then by means of a call back the browser says the server excuse me the server says i'm done sends that information back and away you go you've got the information a field gets filled in or you know something transforms on the client later most of the time this is within a few milliseconds and you don't even notice asynchronous is the preferred way to go in fact it's the only way to go in many cases when you start getting into other uis like service portal and workspace so be aware that there's synchronous and there's asynchronous there's times when you need to have synchronous communications like on submit you don't hit that submit button ask the server for some information meanwhile the browser goes and submits the form and then the server comes back and says i'm done hey where'd you go what happened well it already advanced on that would be a synchronous we say i'm going to submit i have to wait for the server to find out should i submit or abort that would be a good use case for a synchronous communication make this make the client wait until things come back most of the times with on change or unload no you don't need that to be synchronous it would just be it it ruins the experience okay back to my use case hope you got all that that was the intro to you the synchronous versus asynchronous in different ways we are going to oh forgot to mention the other ways we could do this so one way is a client-side glide record query i don't recommend this because all of the methods that you get from the server side glide record which is the main api we use to interact with our database they're not all available on the client side so you're dealing with a partial set of what you're usually comfortable with okay not the best way to go the second way is to do what's called a gform dot get record and you can say go get the information for this record and it will retrieve the entire record now sometimes this is a significant amount of information you say well i need i'm looking at a change record and i need the manager go get the manager you can do that but it's going to get the manager and a whole bunch of attributes that you probably don't need because all you wanted was the manager's name or sis id that's a waste of time okay you just went and got 80k of information for 32 bytes of use not worth it glide ajax lets you control what is requested and what is sent back the response excuse me the request and the response i'm going to show you that with an example of some structured data some complex data that we can ask for and retrieve so let's get on with that use case back to my record producer let me look at the the actual course table first here's the way it looks in a standard form so i'm going to go to my course table and i've got a couple of dependent fields in here or one dependent field for each course i have a track i've got history liberal arts mathematics science and if i pick science it automatically adjusts the uh you see my automatic instructor assignment from the last episode is still working here i've got physics chemistry astronomy if i change this to mathematics i get algebra calculus analytics okay so category is dynamically updating and if you haven't seen that before let me give you a quick peek behind the curtain i'm going to go to configure dictionary it says hey you changed something yeah i know go to the dictionary and if the browser is slow i get to take a drinking break the last of my herbal tea and down here on the dictionary entry under dependent field it says make this field dependent right here okay this is a dependent field and i'm going to use the track field then when i set up my choices on the form and i say hey category here are your choices i say show choice list notice there is a dependent value on here let's do a shift click just to highlight those okay so strategy is dependent on management value from that dependent field it ties these it binds these two fields together so it says these choices go with the track management value these choices go with the track science value okay what i noticed and frustrates me often is that a record producer finally getting back to that record producer that we started 10 minutes ago under record producers i've got a create course well there is no dependent field bothers me okay i've got my track field and i've got my category field as a variables and when i look at i did click that did i not when i look at the definition for category there you can look unless somebody knows something i don't there's no dependent in here and if there was i wouldn't use it because that would ruin my demo okay so i've got all kinds of great information here but i don't have that ability to bind category to track much the same way that incident has category and subcategory i'm using track and category okay you get the idea but it doesn't work here so i'm going to build my own dependency so when track changes it goes and looks up those appropriate choices for category sends them back and i will reconstruct the category list on the fly that's our goal i think we can do it let's get going so we described described we covered our use case let's get into it okay we showed the course record i'm just checking my notes want to make sure i didn't miss anything first thing i want to do before that is let's see if my graphic is still here yes it still is we covered this a while ago but i like to refer to it this is how i structure the apis and who calls what and we are going to start way up there in the upper left corner well no we're not that's where the conversation is going to get started but that's not the way i build things build from the bottom up we're going to start with a script include that says go get me the data first then i'm going to make a script include that references that and then a client callable script include that references that and then a client script that references why am i doing this in layers easier to test more flexible apis reusable content you get the idea i i'm it may feel like i'm over engineering this but i need at least two components one is the script include and one is the client script i'm inserting another script include in there so that i can reuse the server-side content in another script i'll explain that in just a sec that's our goal that's where we're going let me get back to the screen there it is let's start by going to studio because i've already got this scoped application halfway started called cls for community live stream not very imaginative and collapse this i've got a whole bunch of stuff in here including some script includes and if you remember you were around i did some client-side ajax stuff at one point you could see here is a standard good old script includes not client callable as you can tell from that field not being checked and it does just a couple of functions get id get url blah blah blah blah blah and there's a get info which calls the other functions this one that i called instance ajax and you'll find this pretty common as you look through the script includes there's often an ajax component and their non-ajax component if i just had this client callable ajax piece it would work fine with the client scripts but the underlying logic would not be available to any other server side scripts that's what i want to make repurposable that's why i have this extra layer in there so that's where we're going with this let's start by going to create application file or in my case i think it's command shift c is the shortcut in studio technologies for the crazy screen stuff server development script include i'm going to double click that and call this course this is my bottom one this is the gray area down here purple one on the left script includes okay that's what we're going to do this is not client callable this is the server side only and i'll not worry about who it's accessible from now in the interest of time this script does get a little big so i've already pre-baked one and i will share this on portal on on the github repo that we talked about earlier but let's walk through this real quick collapse that so we've got a little more screen real estate service servicenow has already built me out this part it builds this template var course course prototype blah blah blah all i did was say i need a new function in here called get track categories that's going to go into the cis choice table right here with a glide record query and i say i need the name name is table often cases if you look in the dictionary and says choice you see the label table it's got to check this one always check table and field or table and element they often have different names so i'm saying go get the entries from syschoice for the course table category field hey you've got 20 of them great i need to narrow that down just a little bit more i want them where the dependent value is track track came in from where i'm calling this function it's a it's an input parameter the language is going to be whatever the user's language is i yes i'm making this language independent it's very important because you may have multilingual things and you don't want three records for mathematics in calculus analytics and algebra in spanish and german and portuguese you're going to have 27 entries if you've got nine languages so let's narrow this down to the user's language works really well i want inactive false this is one of those weird places and it's about the only place i've ever seen where active is now inactive so remember to reverse that logic and i want to order them by the sequence get these in order okay once i've done my glide record query not not too much difficulty here just filtering filtering filtering to get just the records i need i'll get the query and for every record i find i'm going to create an array of objects list is an empty array up here i create each object label is a get value label value is a get value value sounds redundant but that's the way it goes i'm pulling these values out of the cis choice table and then sequence is going to be a get value of the sequence i want that number uh interestingly enough i just discovered something that should be a value like a numeric value so let's put a parse int which i didn't do before otherwise it's going to sort alphabetically because getvalue returns strings sadly yeah you could probably stick in a use case for glidequery in here somewhere and make this much cleaner i challenge you if you want to look at glidequery if you're a fan of that let's do that now we will get back a number that will sort accordingly and copy that blast it in there there's our code we now have some clearly untested code so this could go either way i want to test this as i build up that stack let's test it so make sure that get track categories does what i expect i have a sample test script boom that says go get a new course object and run the track categories on the science thing and then display this all to me gs.info is our way to output something in scripts background json stringify takes the array of objects turns it into a human readable string it says object and this makes it pretty explain as we go let's go over to my instance scripts background paste run and it says great you have yourself a nice object label physics value physics you get the idea 12 13 14. these are the choices i want when oh where's my back arrow when the track is science what if the track is i can't remember what the other track values were mathematics mathematics math e-matics hey let's see what we get when we have a bogus value run that and i get algebra calculus analytics just how i saw them on the classic form when i pulled when i changed the track value this is what came up in the category value so i'm able to reference this script include to get a list of object great what do i do with that let's pass it up to that next value the script include that's going to interact with our client script so we'll go make that again create new file script include oh there's a lot of scripts in here you just type script that's annoying and i'm going to call this course ajax just to differentiate it from the course that doesn't do ajax very very important very very often forgotten i've missed this more times than i can count don't forget to check this box to make a client script a script include client callable otherwise your client script is going to go hello and no one's going to answer that also changes look at what that does to the template down here on the bottom it used to be var course ajax is class create it now extends this object called ajax abstract hx processor that's a whole bunch of work that somebody did a long time ago that saves us all the pain and suffering from doing those ajax calls we just pop in our thing and we're extending that functionality wonderful uh oh somebody has what is constant course table thank you steve for responding it's in a script include called constants and if you format it in a certain way you can put in your values and your tables i do this because a lot of my apps tend to move between instances and change scopes something that started on my pdi is x under 66238 becomes x under s and c or x under orb or whatever if i want to distribute it to somebody else this makes it very easy to say no i just changed my user table from sysuser to you underscore customer whatever you you have the option of coming here and all of your server side code will respect this it knows what those values are it's like a global constant value for your application rather than oh explicative here i just changed my user table do you know where that's referenced how many scripts not really yeah code search can help you but why you know days of old programmers put their pound defines or whatever right at the top or they had them in a separate include file think of this as an include file there how's that something you that gets automatically included and i can reference from wherever i want okay back to our client callable thanks great sidebar back to our cloud callable uh script include that one is over here on course ajax a little bit simpler and i added some untested code this morning moments before we started broadcasting fingers crossed it's commented out at the moment but what i'm going to do is say you are called get track categories well chuck didn't you call that get track categories over on here yes i did different script includes different methods totally different one is going to be called from course ajax and what is going to be called from course and it says i would like to get the parameter that was passed in from the client script called sysparm under track i got this from the wonderful template over on docsi the developer site when i looked up glide ajax and it says first the client script will do this then the client script will do this there's two minimum requirements here we'll get to this when we get to the client script but it's going to also pass in me a parameter called sysparm under track i could call this track you don't have to call it sysparm under something but as a standard as a recognizable parameter from the client i'm using the same nomenclature that's in the documentation not the same variable names but it's going to expect a variable called sysperm track that's where i'm going to get science mathematics history that kind of thing okay if i got a parameter okay do a little error tracking otherwise you're going to send the other script include off on a errant call and you're probably going to get back the wrong results if anything so first i check did i get a track parameter if i did then let's go call the other script include just like the test script did i already have faith in that because i tested it lightly tested it didn't test everything right didn't do any error checking but i have enough faith in that that if it worked this way in my test script it will work this way in my script include okay oh another discussion going on in the background maybe chuck can briefly show the script include constants oh yup did that thanks mark i i do have an episode on that so steve picked that up from there if you go back in the cls archives there is a i'll try to put a link to that in the in the youtube description and the community link before i uh post this all finally out so note to self go get the link to the constants video i have that i have an app that tracks all these episodes so it's easier for me to find it okay once i get that information i am simply going to return the string value important to remember when you pass information from client to server server to client it's always transmitted in text so i have to stringify this thing it remember this this reports back an array of objects great if you're passing between server function and server function and server function and absolutely perfect you can do that you don't you don't have to stringify and parse but if i'm communicating between two systems on the internet anytime it goes between two things browser and server instance one and instance two it's got to be stringified that's the way the internet communicates it doesn't know binary data types even images are encoded so remember that always a string on the internet so we're going to stringify this and return exactly what we saw from the other script just like what came out of that json.stringify in the debug script okay there's a reason this looks so much like this does let's copy that put it into my script include i don't want to select all that and there it is get track categories get the parameter if you get the parameter do the course lookup and return it i am going to this actually doesn't go in here that would have been a problem this goes in the client script and i think i've already written that part so i'm taking that out okay i'm taking that out i don't know what i was thinking at 5am this morning but that clearly is not the right place let's make sure it is in the client script before i get there yes it is okay i'm done never mind that untested code part let's submit that now i'm set up for the client script there's not really a good way to test this without actually building the client script the client script is going to say hey the track field just changed go fetch me some new values for the category field that's all it is so let's go build that it's going to be on the record producer so do i have the option to do that in here i don't know client script catalog client scripts yes i do record producers are a version of catalog item i believe they even have the same base table way down deep but i'm going to say this applies to catalog item uh track update i have no imagination on my naming today it's going to apply to the record producer create course i remember right create course there it is and it's going to work on let's make it work on everything i don't know applies to an item view no problem plays a target record not a problem type that's the important part on change are we going to trigger this client script every time a variable changes every time it's loaded and when it's submitted i'm going to do on change and let's go look at our completed client script there it is okay first part says if you are loading or your new value is empty i want you to return get out you're not here this because on change also runs on load you can have the same script do the do two different things in this case we're making it exclusively on change that's what this does okay don't forget that because a lot of people write an unchanged client script and then they go put the same code in an onload client script why did you do that because the onchange already runs on load that's what is loading tells you now the fun part from the docs page let's go through this together glide form not glad form glide ajax has an instantiation when you see the word new it says i need a new object modeled after this class glide ajax is built into the system it's not a script include that we can go modify and it says i want to talk to the server side script include called blah whatever's in the the quotes parentheses my in my case it's going to be called course ajax that's the client callable script include we just wrote also mandatory required add the parameter sysparm under name that's the function that's the method in that script include that we want to talk to in this case they use hello world i'm going to be called get track categories i think that's what it was called yes this is where studio is really really nice and this is where i first fell in love with studio because i can have the client tab open and the server tab open and copy and paste and not have to remember crazy function names okay that was that was my first love affair with studios like hooray this is awesome yeah you could try it with browser tabs but then you get into the whole back button history thing and okay regarding ui type i have noticed that often you have to set ut type to all to even execute um i've seen it work with desktop but when you mobile isn't the native mobile app keep that in mind that is the web mobile app so service portal and mobile on that case are the same if i'm not mistaken unless somebody knows more about mobile development than i do that mobile is native mobile maybe you can answer that in the community we'll have a chit chat back and forth okay those are the two key parts glide ajax and add parenthesis part name now i am passing in a track i want the server to do something based on the client value so in my case i'm going to add a parameter called sysparm under track you can add one you can add zero you can add 15 parameters if you like i don't suggest it but you do what you want then it says great i've set this thing up let's go execute now important note about different ways to execute this the most common and most recommended way are two there's two most common and two most recommended there is get xml which you pass in a function to say when you're done server when you're done come back and run this client code okay this is asynchronous server go do your thing i'm not going to make the browser wait and the user get hostile well they have to wait a whole second and a half because that feels like an eternity on a browser window i want you to go back and do your thing get xml wait what it returns is an xml payload and frankly i really don't care for this response.responsexml document element get attribute just to get the answer out of there somebody else didn't like it so a few years ago i don't remember exactly when we came up with a little friendlier version called get xml answer look how much cleaner this callback function is it says here's your answer it passes you the answer object already parsed out okay so if i need my stringified array of uh objects it's already there easy look you can just do a parse int but that's what i'm going to did i do that i don't even remember what i did in my script i have a get xml answer yay hooray okay and it will send me back this part that i can parse out so i've got a function to do the response payload work and i've got it inside of a function that's doing the change that's it this one actually looks like it has two separate functions one is not inside the other i learned by doing one inside the other and that's what works for me you do what works for you i don't know if there's any technicalities like performance or callbacks or stack whatever okay let's go ahead and paste that into my script again here's my glide ajax go call course ajax what function would you like to run get track categories do we need another additional information yes here's the track i get that with a g form get value that's the client side version of hey what's in the track field pass me that and then do a get xml answer i love this because it's so much simpler than get xml now if you had to do a synchronous you could do get xml weight okay you can't do that in scoped apps though look on the community i know there's a common question of how do i do an on submit client script synchronously because i need to wait for that response in a scoped app look it up there's a number of links you'll find them very creative uses and i think one of them uses gforum.submit in the callback function so it i didn't completely digest it and understand it but i know it's a common question and again we want you to try to avoid using synchronous in scoped apps actually any apps okay when you're done come back and run update category that's what line 9 is telling me it'll run upbeat category with the answer object already i'm sorry it hasn't parsed it out because i passed back a string if i pass back a number you get that but this is the answer it's a big old json stringified object and clear out all the options on the category field then go through the list that was passed back whether it was one item or 15 items i'm going to use g form add option with the four parameters there's a three parameter version that doesn't include op sequence how do i know this because i already looked it up earlier here is the here's the three parameter version field name category choice value analytics choice label analytics and you can use that it works great it will put them in whatever order you put them in however if you've already got options in there and you want to do an add option to say no this one goes between that one or this one must go at the end or at the beginning then you want the four parameter version which allows you the index number okay so i am using the index number just to keep it safe because i put it in that object as 12 13 14 here's 12 13 14 because that's the way it came out of the database that's the way it's hooked up on the natural classic form and that's the way i'm going to emulate it in this case as well let's go do that run this client script it's time to test wow that was a long time to get to our test back on my record producers we've already looked at the variable i've got my client category set the variable to unchange dhruv is asking oh i did not set the variable name good catch thank you i want to set the track variable to be the trigger for this debugging these things is not a whole lot of fun you can debug the server side like the server script include that i did debugging when you if you have to get to debugging a a glide ajax call you're gonna wind up sticking a lot of like alerts in your callback function or g-form ad info message so you can see what the server is sending back or what it's trying to send back because there's often a disconnect in parameters or format or the payload just isn't making it for some reason so that would have been a boo boo thanks dhruv plus one for you okay record producer try it name my course i don't care that's not the important part category currently has oh my look at all this stuff that's under here this isn't right because i could be picking chinese and then say history did you see a change now i just have these options so what i should really do is start with no options i could have an unload that clears that thing out because right now it's loading all options where did those options come from let's let's have a little more fun liberal arts theater political mathematics analytics hey i've got a dependent field just from creating a couple of scripts so i call that a success ring the bell or do we hit the coin i think we hit the coin [Music] we'll figure something out here uh by the way we need a video on the on the debugging in studio so we'll do a script debugger video i thought we did something like that in live coding happy hour but i could be wrong the um let's do one more thing didn't plan on doing this but i think it's necessary because we certainly don't want users coming into this script and saying uh picking going what what is this i picked calculus and then when i went to liberal arts it changed to theater what happened can't i take calculus as a liberal arts no you can't it doesn't make sense but i think it makes sense to uncheck that value it is starting out as none but when the form loads it's kind of in this crazy format so let's do this let's see if there's something on configure variable that we can do we can set a default value to none that would start at the top but it wouldn't remove those options come on there we are and we say our default value yeah that's fine default value is done the type specifications i've got this tied to the choices on that other table we showed this before but you can take a known table i this didn't used to be a possibility in select lists until recently as far as i know that you could bind this to the values of another choice table you can do this between forms and tables and whatnot on the server side but when it comes to the record producers and variables no it didn't used to be possible now it is so if i don't want to replicate the choices for track in the in the form and in the record producer i can say hey go get your values from that other list over there that way i'm maintaining a choice list in one place so when somebody says we've got a new track you add it in one place you don't go track down all these other variables and other forms and fields this is really really nice but that's what's screwing me up right here is it's saying go get your initial values go get all the values from the category field on this other table do not need do not want so can i get back up to the top of the list and say nothing and say nothing here well i guess if i save that it doesn't matter it should say you don't need this it does say include none i want to see what happens ah pdi you're so fast today okay that was nice let's go try it out again record producer create course nothing in the list that's where it was coming from it could also be coming from if i did variable category it might also if you are if you're not using that pointer method of saying here's the table here's the field go get your choices from that other place down here it could be coming from the question choices down here that somebody put in so look down here in the related list because it may be getting those which may be different than what's on your form might be the same who knows so that takes care of that we now have a nice record producer with table history boom mathematics three new choices that's really how dependent fields work on the back end how they work in a classic form we've just emulated duplicated whatever simulated whatever word you want to put in there we've built this out with script includes with a client script and bonus content because the way we built this remember we have our course script include this may in fact be called from flow business rule anywhere you've got server side code i can now leverage this get track categories same way that i created that interface from the cloud script the client callable script include to this script include i can be hooking this up to other pieces a scripted rest api a ui action it really doesn't matter i've got all kinds of opportunities in here because i have that in my gray library box of go get me some stuff if i had made this a client callable script include in that teal box over on the left i can't hit it from anybody else it would have done its job for the left side client stuff but no good for other server code so that's the bonus that i give to you today think about that when you're architecting your script includes use those script includes and flows and subflows and actions as library reusable components write your code once test the heck out of it and then reuse it elsewhere in the in the platform that is going to do it for today i appreciate you sticking around thank you thank you to the internet deities that allowed me to do this without fault this time the technology on mine is working the technology for the isp has worked now they're going to send out a technician tomorrow go i don't see a problem and then thursday it will show up so i invite you to join me thursday for another episode of code decoded where would we talk about mail scripts so if you're into doing some mail stuff and customizations and you've got to trigger emails and you need to put some scripted content in there and do some data lookups join me for that got a wonderful wonderful example of how we can do that if you haven't dealt with male scripts before then you're going to learn something i invite you to join the community participate the community community.servicenow.com and get engaged with that wonderful wonderful learning experience lots of great stuff out there for now i'm chuck tomasi thanks again stay safe learn share and be helpful i'll talk to you again next time take care bye [Music] you
https://www.youtube.com/watch?v=nBiVb1tKHA4