logo

NJP

Creator Toolbox - GlideQuery

Import · Apr 07, 2021 · video

hello and welcome to creator toolbox this is the web series that helps you servicenow developers low code no code pro code anywhere on that spectrum learn new skills and put them into your toolbox so that you can become more effective at your job my name is chuck tomasi senior developer advocate really happy to be here we've got an awesome topic that i know a lot of you are looking forward to or some of you may be looking for more information because our next person andrew barnes has been writing some blogs about that but first let's finish our introductions andrew hi everybody i'm andrew barnes developer advocate here at servicenow i have been developing on the platform for about seven years and been doing this role at servicenow for two and a half years and just a teeny correction i didn't write the blogs i'm just helping publish them for our that's right special guest uh who will introduce himself next which is peter hey yeah i'm peter bell i'm a software engineer at servicenow and uh i wrote glide query which is uh kind of a new take on writing server-side scripts on the um on the servicenow platform so it's intended to be kind of a safer api that uh takes the place in certain cases for glide record so if you know a glide record is you can usually use glide query as an alternative it's not intended to replace uh glide record per se it's just more of an alternative in case you want to experience the ui with the experience the developer experience uh it's a little bit more modern i suppose and so so peter attaches tell us a little bit about you the the person and we'll get into glad query in a minute sure um so i've been at servicenow for two years i'm a software developer i've been i live in the seattle area and uh yeah i guess i've been in the industry for about 15 16 years now i really like software development and so it's it's one of the it was glide query was more of just kind of like a fun side project i was doing on weekends because i code on the weekends sometimes i'm weird like that thanks peter my name is brad tilton i'm a developer advocate at servicenow i've been developing on the platform for about 12 and a half years now and uh i am i'm excited to learn about glide query today as am i i've dabbled with it as we'll see a little bit today uh but i've got some questions so peter you were telling us about glide query and and by the way you are not unusual among this audience for coding on the weekends and just spending time i get most of my productive work done on holidays oh really yeah when when but everybody else goes on vacation boom i go to the keyboard and i start banging out some app or enhancing something else so it's a lot of fun so you're giving us a little bit of the history of glide query what was the impetus behind starting that well it was part of it was that it was a learning experience for me i was trying i was thinking what would it be like to write a new api that is something that i would enjoy myself using you know in our team so our our team i worked for the itam team uh we were writing some software asset management applications and um i wanted to avoid any kind of common mistakes that we made in the past where we were writing and maybe we missed the we thought there was a field that wasn't actually there and so um we queried and we didn't realize it was just not working but it was silently failing so i was like well what if we got rid of that just the api couldn't allow that to happen that would you know and what if the experience was more of a kind of a modern javascript uh experience more with uh like some of the newer apis that you're seeing in the node world so it yeah it was is basically trying to reimagine what a new ui would be like and what and and it has a different philosophy than glide record in certain ways it's it's not exactly the same so you you do have to kind of take out you know relearn a few things but i think that it's approachable enough that we've had some good experience with uh with people catching on to it and really liking it and are there any examples you can think of where glide record would still be preferred over glide query yeah there's uh well currently there's limitations so it's relatively new so there's no support for encoded queries for example that's if you if you're used to typing an encoded query then uh currently glidequery can't help you there um we've had requests for that and we're um very interested in adding that in the future but uh currently there's no support there's probably a few other i think there's trends trending we don't have support for that i think it's one of those things where it's probably good for the 80 or 90 of your queries um you know it's good for those but there's probably special scenarios where you uh you would probably want to fall back to using glide record things like pagination where you have the choose window yeah glide record sure we don't have uh we don't have that okay so yeah another yeah stay optimistic another example is in one of your recent blogs uh you said when you're doing aggregates and you need to do something like uh account um you know one of the one of the functions that glad aggregate does already uh you said go ahead and and use that directly i believe is what you said um for performance issues or performance issues i'm trying to think i don't recall exactly what did i write that that um be that's that's a common problem for us is going and reading our own things yeah because when you were when you were in the moment uh it was more clear um i actually probably have it handy yeah there okay go ahead yeah that's those are some of the big ones that uh and existing apis like like i would if you have a function that takes a glide record you know you can't just throw a glide query in instead you you probably want to still pass a glide record in there because that's how the code uh was written so for uh existing code that already is kind of um written in glide record i would just i wouldn't necessarily uh just try to pass a glide query instead because it's it's probably not going to work for you well what do you say we take a look at some examples andrew give us a setup of what we're going to be doing today awesome so um chuck has got a karaoke app that he's built in servicenow and you use it every week and when i was looking around for some script includes to get some examples from so that i could practice uh can you know using glide query since i'm not actively writing anything that really needs it right now so again to peter's point um i wouldn't suggest going and converting script includes but that's what we're going to do today because i don't need to write any new code right at the moment and already having known um working functions and a goal is a good thing for learning something new uh so that's that's what we're going to show today is we're going to convert two um functions uh one with cloud record and one with glide aggregate over to using glide query and then we're going to look at some that we've already converted so i've converted some chuck has already converted some previously not even related to this show and peter took a stab at converting some of them and so i'll be um converting those i am still really new at this uh and peter is definitely going to tell me when i am being bad and where i can get better because this is a learning experience for me and hopefully it is for all of you uh to to see how you can you know accelerate learning uh glide query and then know when to bring it into your development so with that i will go ahead and start my screen share and we'll get rolling there we are so i am in my karaoke uh app um and we have got two script includes that we're gonna look at today um so one of them is called rating and the other one is called user profile and we are going to look at both of these uh today we're going to start with rating and i've got this first method here i want to convert this one over uh to using glide query so first we need to look at it understand what it does and then work it converting it so looks like we take in qid raider id and rating and we've got a glide record here on nine um that seems to be creating a new record with these four values that we took in uh and then let's see what else are we doing with this it basically inserts a record into the rating table so when somebody hits a five uh you know the fifth star you get five star rating so it says andrew raided this particular the queue is it a cis id pointing to a cue record that has who's singing what and when and where they are it's managing the whole cue process but the rating is related to the queue basically a performance so it says andrew gave this performance or cue entry a five and that's what you know lines 11 through 15 are doing then it says hang on a sec i got to find out who what what the customer is for this so that i can log it and that's really what line 25 is doing it's saying go log that andrew gave a 25 a five star to this person so it's creating a log entry that we can come up later and go how did i do so after i perform or after you look at your log it says i rated chuck five stars on singing you know whatever technically that should probably be two functions now that i think about it in there somewhere two things there um there are two things in there yeah let's let's start uh well is there anything else that we need to understand before we start converting this peter uh see well i would probably start off with just doing the insert that looks pretty straightforward with glide query you would do the same thing up front we would new a glide query with the table name just like you do currently um and so let's uh well first let me go ahead and uh you know knock this one out sure i think i may have spotted an issue in the in the logging part but let's focus on the insert record first so i'm going to do a new global dot glide query and we're going to copy pasta because i don't type anything because i'm i'm a bad typer no i'm actually a print pretty good typer on bad spelling um so and and do note when you're in a scope uh you do need that global dot um so don't don't don't be fooled by it looking like it's working um without that because it it'll it'll render like it like it looks like it wants to work and if anybody's wondering about that constance rating table thing that's where the table name would normally go so it would say x underscore or by or karaoke blah blah i i've tweaked this thing for the last two years and i got tired of maintaining table names all over every place from service portal to script includes i i do this in a script include so that my table names are all defined in one place and it's frankly it's easier to read for me especially when you get to like many to many tables go uh i don't even know what that name refers to and so when i was practicing um the other ones i i actually went to uh the documentation and two there's a handy uh tag for all of the blogs that peter has been releasing is just called glidequery so if you find any of them these hashtag glidequery at the top click that you'll get to this page which will group them all together for you and so you can scroll down here to one of the earlier ones which is about inserting so part two is about inserting uh and come over here and look at it and go oh okay i do a dot insert and you know feed it uh the pairings let's let's do that then so we come back over here and we say insert that's very more modern and we need to do something like queue so those don't have to be quoted is this just json i would expect the the property names have quotes around them um i'm not sure peter we lost peter lost peter he disappeared he ran away we asked too hard of a question i think it probably works either way right so i will proceed as if i if it works and we could try it out okay until peter comes back so if i read the blog correctly we are looking yeah he's got he's got quotes oh he doesn't over the strings over here he does i was looking at the stuff in the comments below though but that's the response um uh so it doesn't look like i need to do anything other than uh because i want to actually do something with this uh because you're referencing you are like you need it later yeah okay and then make a note to look at that script include because that reference to the field and the customer record ain't right okay so um and dirk says they do not need quotes and i i believe dirk until peter tells me otherwise [Laughter] so this looks like uh i'm i have replaced it i'm back sorry you guys lost internet connection welcome back peter we were just wondering if the properties like q raider and rating need quotes on them or should have by best practice in that objective um you don't need that no if if it has a space in it for example or it starts with a number uh then you would probably need to put it in a in quotes otherwise okay so it's just a standard javascript json notation yeah yeah it's just a a regular javascript object so you pass it that object and it goes for each key it look it the key is the field name and then the value is the value that you want to insert and then it um it returns what's called an optional but for now i'll just say it's just a way of being able to fetch back that data you just newly inserted or you can transform the data as well we are definitely going to talk about the optional in some of the conversions because some of them so i'm using them in the some of the conversions and user profiles script include and and we're definitely going to talk about those uh sure i had fun learning about that and i'm not sure i got it all right but fun yeah and fun fun is good yeah fun is great i love it uh i would also rename that variable just so it's not confusing that's not a glide record that's being returned back it's just it's a rating object or what have you whatever you want to call it i actually uh was going to mention that um so i would uh you know i would change this uh as well um so let's uh call this um what do you want to call it you could call it rating opj or something we already have a rating variable being passed yeah so and then and then what we have to see is how we need to access these other things down here if we need actually rating gr yeah so it looks like what you're trying to do then is your the in the record the rating table has a cue field we just inserted a q and then i'm just looking at this uh customer if we um so i guess what we could try i'm actually curious to see if this would work on line 22 you have that ending of the object insert actually when you insert you can also tell it hey i want to insert but when i read back the variable i want you to also pull in some extra data yep back from that insert so after that bracket if you did a comma space and then an array we could i wonder what would happen if we did q so put in create an array after the comma and then purchase just uh an array like square brackets yeah and delete the queue yeah we're going to be pulling this out dynamically like we did the json object we're just defining it um something like see if i can but i'm i'm not tracking what you want me to do so i'm sure you're doing it badly well um let's see if i can show you what i was gonna i'm writing it right now and i'll send it to you okay customer i'm just curious if this would work something like can you do like q dot customer as the first element in that array yeah if you put us inside the empty array if you put start a string quote and then um q dot customer and then we'll use a flag so after the r oh wow but i need that that it's the dollar sign yeah for yours very thin and then display all caps so we're kind of getting into advanced step advanced uh things right off the bat so this is what you would do i'm fine with that so and this is this is in the blog for um i know i know which one this is even uh let's go here and we were doing it's one that says flags right here part five dot walking in flags yes so yeah my field flags is here and uh this example uh is straight from right here that's right there's there's our flag so that's a way of saying hey normally you if you just say i want the um thick the rating dot q it'll return the id back to you but if you if you add that money sign display you're saying actually i don't want the cis id of the of the customer i want the display value of the customer so in this case we actually seem to want to get orb karaoke party return a second one that dot walks all the way down to what you want which okay so something like uh just keeping oh so you want the party yeah because we actually need the dollar display though you don't want the display because then you can't walk anymore this no you need um is the customer yes versus yes but leave off the dollar display okay so something like that i think that's a table name though um this is not sure why i'm retrieving party id it's never used again well then we should stop doing that and it is what's customer gr used for just to use the display value which is using 29. yeah and rater id and q dot song oh there's another one down below we're gonna need uh the song id okay we're gonna need u.s song so cute i feel like we're playing chess you have to look ahead a few steps yeah what do we what were we doing and yeah you're just some people you will see your old code and go why did i do that it's probably left in from some legacy thing that i was trying at another time okay okay so the only reason it's using the only the only purpose of 26 is for 29 and we're already retrieving 29 so we don't need 26. yeah we don't need 26 anymore yeah this is nice i like consolidating so the rating object now instead of that custom gr there on 29 yep we can right change that to cut the rating object dot q dot customer money sign display yeah okay so you continue to use the the the dollar display to invoke that every time yeah the reason why we um and then on 34 you'd want to change that one to rating object dot q that song yes in fact just the rating object needs to change oh yes just this is getting cool there we go so i may have missed this do we still get so your rating object does it have uh all of the fields on the rating table in addition to the two that we passed in the array or are we only returning those two in the array or requesting it will return back yeah that's a very good question it will it will return back all the newly inserted values so it will return and rating and it always returns a society even if you don't ask for it okay but you don't get okay things like but we don't create it on and create a date and all that good stuff no okay just uh society all right so line 36 you could change that to rating object dot sys id um dot q dot wait it was pretty important oh yes okay that was from up here yeah yeah so we need oh you're right yeah totally forgot about that yep great is this uh is it what's your pattern of course uh cis underscore id okay so you didn't change it good i appreciate that thank you don't mess with some people like and yeah and then well it upsets me one one thing that i try to do is keep things uh what you put in is what comes back that's why we use that money sign flag that it's like why i use money set it wasn't my first pick but it happens to be that in javascript money sign is one of the only two non-alphanumeric characters that you can use in a variable name in javascript yeah i don't want to go near that no underscore is pretty loaded in the service now no i like this because it jumps right out at you yeah to me as a as a service now programmer just says hey this is my display value yeah all right so um one thing that we uh i guess because we did insert q we know the q is there so i was just thinking if if q is null we're trying to we're referencing uh ratings object dot q dot customer display so um i assume that here right now but the queue that is being put in is correct and it actually has that because if q is null then line 15 would fail right where you're trying to you know walk an object along with but that's true i mean technically it i'm sure there's probably a way to make it null but the rating widget will only show up if somebody is currently singing okay and you're you're actually the the um scripted rest api that's being called from the widget is getting all three of those parameters who's singing how andrew rated this queue entry with this value yes okay okay uh so see um i think this is uh pretty good for this first conversion yeah la you want to move on to uh the glad aggregate one yeah that's actually a good idea okay so let us scroll down our script include um i didn't expect to get that much meat on the bone already yeah i wasn't i wasn't actually uh expecting this too i was like oh we're already using you know insert and then fetching back extra properties i didn't think that um and flags go through that before so here's one of the ones uh chuck is already converting we'll come back to that one and then i'm not sure that's actually the best way to do it but it works okay then down oh uh before we go further this is another limitation maybe or not yeah i think yes we do support uh using glide record secure you can opt into that there's a method called i remember that there is a method that ah it's called remember okay it's called with ackles and if you do with acls then it will use glide record secure behind the scenes so it'll honor acls but you can't use glide aggregate functions with that only regular glide record once right that makes sense that's really a better name anyway for yeah record secure because that's what it's doing with echoes yeah so uh we've got this uh glide aggregate here on dude and it looks like we're getting uh the average from the average rating customer from customer id and we want to uh rating is more than zero and we want to uh group by song so okay and then we're going to loop through that so we're getting the average rating for a customer by some okay and then for each one of those we build an object to oh wow okay and i thought this would be uh really useful for us to go through because you uh if i recall from the uh the the streaming one's like you're already you already packaged this stuff up like this yeah okay uh so this is the first time i've looked at this so i'm kind of let me digest it for a moment but surprise surprise yeah it's a coding interview and uh in front of other people okay yeah but uh but i'm the one with the the fingers on the keyboard so it's it's it's me being interviewed not you if i if if uh if it's done poorly it's my fault it's my fingers well let's see um like so one thing i would say right out um right off the bat is that with with glide query right in in glide record there's glide aggregate and there's glide aggregate um applied record and glide accurate in glide query there's just blackberry so whether you're doing a um an aggregate query or you're doing a more of a traditional query both of them will use glide query and that's that actually is by design because it allows us to reuse queries between the two so and if that's mentioned in the blog posts it most certainly is but that's a powerful ability to reuse queries for multiple queries um yeah i think it's probably at the so down here uh you've got an example of like y uh so that you can you know do one aggregate and then one not aggregate and not have to even change your your activity because some some people like to build a query up and they're like all right i've got this query but i don't have to do it every single time well with glidequery you can build it up all the things that are in common with the multiple queries and then reuse that query multiple times oh sweet so that's almost like a procedure yeah kind of it's it's uh queries themselves the glide query objects are basically you can think of them as these immutable objects that you can pass around and they don't change once they're created and um i can uh and that enables me to be able to um to do to to reuse uh reuse a query so here you've got uh sorry google i'm trying to think about where i can load on that in this whole app so i went ahead and copied your your example uh from that blog so that i didn't have to like toggle back and forth yeah so so that we could look in example one and then build ours down here yep so let's go ahead and do uh you know like [Music] yeah okay live query this guy hey stop that i missed okay and then we need to come down here it wasn't off by one bug aggregate so in your case we want to do the average of average rating has that already been averaged why is it it's called average rating because it's this is the top rated so when i say hey what songs did i do best at it's actually taking the rating record itself this is across the queues isn't it i found out that doing the average of an average didn't quite work out because the user has an overall average let's say i'm 4.25 that's across all performances all songs all dates everything it's kind of like like i said my uber rating my customer rating but the rating table itself has an average per performance this this was going back to the raw source no i'm sorry this is on the q table i wasn't looking at it right this is on the q table this is the average of the averages so this q entry if if i had five people that rated me you know 3.75 let's say yeah i feel like we're doing live coding beer rating right now but uh if i had a 3.75 and then i came back and sang that song again it was 4.25 the average of those two is going to be 4.0 so i'm i'm this is averaging out performance averages okay so we need to add uh some queries here for the customer id that we were passed and we want the uh the average rating field to be greater than zero so what's the best way to approach that well whenever you see if you where you would use add query in glide record you use where which is kind of like the more of a sql style so you would want to add the same where customer is customer id you have two wares or can you yeah you can add together you can um by default they're anded together so you just need to put another under there okay and so i can just average yeah and it's it's very similar syntax it's called where but it's the same idea as add query and it behaves it takes the two our three yard format yeah and so our group eyes the same our uh you know our aggregate is very similar uh so we're all the way down to the query part um so what's the having part that i'm looking at 172. how does that play in so that's so that's copied from the blog post so we don't really know that we're just copying we can probably delete that query but having is that's it's a good thing you brought up because having is whenever you use group by um you having is similar to where except it's at the group level so it filters groups right uh so it's a it's a pretty powerful thing it's actually supported by glide record although the documentation isn't exactly it's not always easy to find documentation for having but it does exist you've seen that i totally forgot about that right yeah it's it's a pretty powerful thing when you're doing group by aggregate queries yeah most of the documentation for that uh it that is public facing was written by me and it's on cloud aggregate okay yeah so that 169 uh query isn't actually relative to to what we're doing right now right but um we're done with this guy now yeah but that was a good segue sets it up and what is count object going to look like at this point well at this point we let's look at our old code we were um we were looping through that glide aggregate online 178 so and then for each of those uh groups we're creating an object and pushing it into a pushing it into an array right okay and i'm trying to so what is it trying to do it then it's going to take that 187 and beyond just does a sort and kind of a trim and says all right here's here's what came out of all of that okay oh i see so it's trying to get the display value [Music] but let's let's uh let's pretty much ignore anything below any 85 right just just look at this okay we should probably look below there but i'm going to scope us to just down to 185 for the purposes of what we're going to do today sure is that display value you're going to give us an issue uh it might this might be another case where we are running into a limitation because we're using a glide aggregate but we're fetching back data from a i'm trying to see if i use that song property anywhere else in there so we should be able to get the display value from song because since we're doing a group by song glad aggregate will return us uh songs data so i don't know if you're handling that but glad aggregate would be able to give you songs uh display value andrew scroll down just a little bit more i'm not seeing a song property used keep going list [Music] i don't think line 181 has any value here unless i'm missing well then deleting code is nice so what you can do yeah i want you to just delete yeah maybe one goodbye and so the way to start to begin the glide aggregate call is to excuse me the glide query call is uh is to select so what select does so select always returns a stream and a stream is the glide query way of of processing multiple things so in our case it's processing multiple groups so we don't need to pass in any uh field names for this we would just call select and now we have a stream of of groups because it's being grouped by song so um well before you put the semicolon now we need to figure out so before we were getting we're getting an array one thing we can do we can call two array if we want um so at the next line or oh right the next one okay so this is this is way one i'll show you two ways to do this so two arrays go ahead but there's one limit to there's one uh limitation with two array and this is by design is two array requires a number up to 100 that you can pass and um and that means it'll return that'll do all the work of returning the array uh so if you try typing in 100 there and now instead of var count object on line 170 that's your list so that has that has that is the list of groups it's probably in a slightly different shape but it's um yeah so this is our groups yeah well it's going to be whatever is consumed on 188 and beyond uh i mean you could literally call that list average rating so that will have the um yeah so that that takes the place you don't need 180 to 186 anymore however um the shape it whereas before it was an object with rating and id i think it will be slightly different i think it will now be oh let me see what will it be i want to do a quick chest and see what it looks like yeah if you pass that uh yeah try if you run that you can run that in the background script you have to pass in a customer id which i think is a yeah that's true i don't know if andrew has any rating records though yeah it might not be able to pull anything out but we'll find out yeah this would be interesting i could probably generate something real quick yes it's a system user right everything in the key table you have some though right i have plenty let [Music] ah oh heaven forbid and my pii has just been exposed your sis id and your side instance is successful your email is your first last name at gmail that's so that's pretty broad i i make no claims about trying to hide on the internet so this is a laugh every time godaddy says would you like to upgrade to the privacy package like i've been on the internet since the mid 80s it's way too late uh go ahead so what i would do is i'd do a json i would do a gs info yeah gsinfo json.stringify i have a keyboard macro for this baby yeah liz i use it all the time yeah that's uh this will be interesting there things so you could see what it looks like it it does look different so there's each object specifies which group it is so in there we have the group it's a because you can group by remote you can have multiple crew spies yep andrew can you do me a favor let's just put a couple more args in that stringify it'll beautify so we yeah tell it to beautify that is not oh there we go oh i'm glad you picked you are coming here before which is just the magic makes it look so pretty there you go much better so yeah that's what the objects look like so because and it's shaped this way because you you could see each object has specifies which group it is um and it because you asked for an average it's going to show you the average value in there too so you could do multiple operations at the same time you could do an average you could do a sum you could do yes okay you could do count sum max min all the all the aggregate functions and you can also do multiple group buys so in this case we're just grouping by song so that's the only thing in there but because of that you have a group dot song and a what was the other one it was ripped out song an average dot avg rating yeah okay so basically the code after 188 needs to be tweaked a bit yeah and that's that so there's a limitation obviously for the um uh two array only goes up to a hundred yeah and the reason why we put that in there is because it's basically to protect people from shooting themselves in the foot we recommend generally if you um if you're doing that you should be careful uh sorry i'm sending you the other way of doing it which will um it uses reduce actually so and that's from last week's blog yes so if you want to know more about that you can um you can check it out i don't think we've ever been better prepared with blog entries than this this video yeah um go ahead peter oh you go you go oh um so that was cool but before you know in the interest of time uh we've got about 13 minutes left i wanted to look at a couple that i converted that i had some questions about sure um so over here in the user profile script includes so same app um i did did some conversions over here so here is the previous uh glide record it was a really easy uh you know check to see if uh this profile existed or not um and i think i got it right but i didn't have that looks great that that looks i mean it looks i haven't tested it either but it looks correct to me in fact you could just return at one night at line 19. i and i almost did that so i was checking out um you know all of the the optionals and the cool things you have and i was like oh sorry there is one thing uh it's slightly different syntax there's one mistake so after um 19 so you can do get just like that but it only takes the primary key but that's a good idea to add so what you would do aware user yeah it's um i did it work for you because i did not test this but i was getting it from the documentation okay well maybe it is i mean it sounds like glide queries get operates a lot like glide records get one parameter is the primary key two parameters is field and value uh uh well the the writer the author doesn't seem to to think that but let's um i was looking over here in uh yeah that's the option i'll get yeah there was an example of glad query in here that i think used it right here there it is so yeah what that's doing is it's you pass in uh get and then the primary key it only takes a primary key that you can't specify a different field so okay and yes one two three four is the supposed that's the society that's the society and then first name last name is what's going to return to you oh okay i i was fooled by this by the syntax here of oh looking like how the glad record get here is especially since this isn't a society um yeah into thinking that was a field name nope okay so what would we do to fix this change to select yeah i just sent you an example in the chat it um yeah so what you what you you could do is put a where clause there so where user i just changed that to where and then select the next one right that's right select once i have been reading the blogs before i publish them that's great so it's before um yeah select one what that does is it it just says hey i only want one record if you do select it returns a stream which is multiple but select one just gives me an optional saying just give me this one thing and behind the scenes it's also calling set limit to one which is important when you're using glide record because it's better performing yeah um so yeah then you could just and then and then what you were saying was i can uh you know just since i don't need this anywhere else i can just do this nuke that that's right that makes me nervous i like burning variables so i can stick a gs info in there oh yeah so um and then um did you have something else on here uh well it was something that was more one thing you you can do if you were curious about like hey what's inside of that is you can um this is a little undocumented magic if you're into that kind of stuff you could after after the select one you can add another line after select one do a dot map global dot all caps gq that's glock short for library i think it's json debug um dot dot dot json all lower case uh and then capital d yeah i think that's what it is so what that will do is we'll map the values but it just passes it through unchanged while printing it out in the debug stream and you don't need a there's no parentheses just parentheses is that does that show up in the system log where does that show up it'll show up in the system log if you're running it it uses gs.debug so wherever you would see that um so it's hidden like the session debugger for you i think so yeah it'll run in the background script you'll see it there but that's all ladies and gentlemen magic so that's something i personally use and it does the stringify for you the pretty printing so the last one i wanted one step ahead in our last couple of minutes was um where is it is it this one yeah i think it was this one [Music] yeah so i didn't uh comment this one out yet uh but i i tried to convert this one and i was like oh there's some some interesting things what was it this one oh yeah down here um i wanted to actually talk about uh what he's returning here and how i can uh make that a little easier with my glide query here this is one of the most annoying things about glide record is everything's a string including your boolean values yeah well that's something i should mention in glide query um it tries to return the appropriate javascript type so if your column is a boolean it'll return a javascript boolean and if you're if your column that you're selecting is let's say a an integer or a float or a decimal it'll return a number back a javascript number so you don't have to call parse tent um on all those values back um and so on this one i think i need to again so i you know i'm gonna just change that tool i learned a thing and i was bad um so i'm gonna have to you know do this uh so that's aware now um and then i was using this present you still need a dot select after that do you not uh yes you do a select one there you go um and then i was using the if present to do that check to see if i you know got it and then perform this because what we needed to do was uh do an insert if there wasn't one okay so this is uh it's kind of like a a search and if you don't find one insert i see so okay so i think that this looks and so what i did what i did was i said okay well uh you know this is just straight uh you know something i just need um but i said you know do an insert and set these values okay um yeah but what i wasn't sure is if i could do this profile gq inside of here like did it you could did i do this right because i i wasn't sure uh so you haven't you we don't yet have a profile gq because that's the thing that you're processing online 43. so we have output yeah yeah so we don't we can't use profile gq you could put um another glide yeah exactly so you could put another glide query inside of the if present uh to insert uh into whatever table that you wanted okay because i don't actually need anything on this guy all right right like i didn't need that trick is going to be getting back the values from the existing record or the values from that newly inserted record so that we can build that object that gets returned out of here yeah oh yeah because i want them to be the same yeah i wanted to be the same later um so what i usually do i think there's uh there's a method called insert or uh update incident i looked at that and that i didn't want to update it because i didn't know that like i was like maybe i shouldn't be updating because maybe those are different values but this this wasn't intended to update the record if found it's just consuming it if found which so i i thought about that and that's probably how we should go but i since i didn't write this and it wasn't doing an update i was like uh maybe i shouldn't update is this something where you want the uh you just want to ensure that a certain record exists like if it doesn't exist and create it otherwise don't do anything okay it's it's go get my profile but if i don't have one go create one for me and that will be useful okay but but i think an insert or update will be fine uh since it shouldn't it shouldn't actually update anything if it is but will it retrieve could you consolidate that into one call and negate the yeah that is that would be one call so that's a the answer yeah update is one call and then we would have that one object so i think it'll work here but um i'm gonna wrap up the screen sharing yeah there's more story too much fun there's a lot of story here and it's just uh this has been really good for me to uh start picking this up and learning it again um so i'll stop my screen share brad um but i want to reiterate that don't uh for the purposes of learning sure go rewrite some existing functions um but you know once you're once you're ready to use glad query which could be even before you fully learn it do that on on new new code uh don't don't take time to rewrite old code um you know for your for your actual organization in instance for this purpose um you know we're not saying go rewrite all your stuff with glad query um i was just using it already written examples so that i didn't have to come up with new ones if it's working don't try to fix it yeah it's working leave it alone if it ain't broke that was really cool thank you so much for helping me so much uh through that peter um i know i have learned a lot in the last uh a couple of days working on this and all of your blogs are so fantastic i really appreciate you writing them and we've got at least a couple more left it feels like um and with that i'll hand it back over to chuck to wrap us up all right any special announcements we've got brad well uh something exciting happened was it last night or this morning uh where you can now register for knowledge21 so that's pretty exciting get in there see what sessions are available favorite them and in the coming few weeks you'll be able to register for actual sessions but today is just registering for knowledge and seeing you know seeing what's available very cool i think that's the big one we've got other stuff coming up but stay tuned to our blog entry stay tuned to the newsletter all that other stuff if you're not already part of the developer program please go to developer.servicenow.com sign up and you can find all that information there until next time we're gonna have more good stuff for you on creator toolbox and live coding happy hour and tech now we've got a breakpoint podcast coming out about more about the details of creatorcon we're going to be recording that with jason mckee shortly so stay tuned and we will see you again real soon bye everybody

View original source

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