NOWCommunity Live Stream - API Adventures - applyEncodedQuery()

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[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 and this is June 1st 2020 happy to have made it to June this show is the show that brings you the thought process the journey of discovery the learning behind your questions and comments on the ServiceNow community which is what you see right there behind me you can find that at community service now.com and join the community ask your questions participate to become a subject matter expert it's a lot of fun it's it really is one of the it is the not one of it is the best online community that I've been in in over 30 oh my we're now up to about 35 years of online community content from me in some various shape or form good morning to everybody who's joining yet it is great to see you online you can find this on youtube at the URL that you see right there youtube.com slash user slash service now community is the URL as you I'm not going to answer any questions in the chat if you want to do that you obviously go over to the community and post your questions there I get a few on LinkedIn that I often steer over to the community that's because there's hundreds of thousands of people in the community if you're asking on the chat I really have a tough time answer as you see it's purple day so we're going to be doing an API adventure this is a follow on from the last one so you're gonna see some similarity in what we did with condition filters and this apply encoded query they tie together very nicely and then as I mentioned Thursday I'm going to be doing a special episode on rebuilding the loaner request app then I'm going to come back to this topic again in another shape or form so there's a there's sort of a series that's following along here between last what was it last Thursday this Monday anyway you figure it out well you just have that special one planned for June 4th tell Wow everybody's signing in thank you for watching this is a great time we also offer this on Twitch over at twitch.tv slash now community if you're watching there thank you very much I can't keep an eye on both comments at the same time so I will do my best through the show purple yes API dhruv's got it it's API so it could be a REST API could be a script API today it's going to be a script API we're going to be diving into a method that isn't documented I love these because they should be this is called apply encoded query and I'll introduce you to what an encoded query is if you're not familiar if you are relaxed chill out take it easy and we'll come back to that very quickly where are we we are up to Knowledge Week five this week week five of six knowledge is still going on bill McDermott's keynote is on Wednesday so mark your calendars for that govern and knowledge dot ServiceNow com signing go to the agenda bill to find out what time works best for you and I plan on watching at 8 a.m. Pacific time which is right in the start of my morning I was trying to figure out when that is if I had anything else that was happening before after not on Wednesday this show is on Mondays and Thursday so it bounds that and very nicely I will continue to burden you this content on Mondays and Thursdays at 1:00 p.m. UTC I think 2:00 p.m. 2:00 p.m. UTC 2:00 p.m. UTC I forgot I've moved that decades ago well it feels like decades ago we also have a webinar coming up yes Tech now is coming back on the 23rd with episode 76 about the flow designer and integration hub changes that we've put in in the last 18 months it's been 18 months since we did an episode on flow designer and integration hub and there is a lot of stuff we're calling in Michael slobotnik as the subject matter expert to bring us that content and show us what's new give us some demos he's going to do a great job we had a discussion on what was it last Thursday at our team meeting and he's got a great lineup I'm gonna follow along with him and I am already planning out to July I've got to get my write up for July July is going to be the Paris platform features right after early access comes out so Paris early access is end of July keep your eye out for that if you're using a personal developer instance what you can get at developer.com I'll get to that in just a second for whatever reason my bail didn't work let's see if we can make that happen there we go I got to get a new soundboard this one doesn't like to work in the background but go ahead and sign up bitly /tn 76 reg is where you want to go and we will bring you all the goodness about flow design or an integration hub we're calling this our 20/20 update did you get you going with that we will be doing a little bit of scripting today's show hence the purple shirt you can find out more about learning about JavaScript over at bitly /sn - learn jas if you want to learn about javascript I just got a comment last night somebody's going through the series having a good time learning a lot thank you very much this will help you go from a system admin to beginning a developer get you set up for the scripting course lots of great stuff in here it's been up for Wow it's coming up on 11 months already it'll be a year in mid-july that's hard to believe seems like it just and it's gotten a lot of great traffic thank you very much for everybody who's been watching those videos commenting on them putting your answers in the comments it's been a really good time yeah another undocumented stuff ain't it great I'll work with the docs team to get that done the code I have for today will be available in github at the bitly /sf CLS link so you can find that there and I think I had one more oh yes personal developer instance over at developer.samsung.com you can get Parris when it comes out all the free learning plans developer meetups you can find those at meetup Dodson's now excuse me meetup comm slash pro you think we'd have a short URL for that right from ours but we don't so go to that URL we are having lots of virtual meetups these days and you can attend meet in other countries even other languages like like we did last week in Stockholm that was fine so let's get started on the topic of the day now that we have that out of the way I think that was pretty much everything I have my personal developer instance and what I want to show you first let me get my notes up side don't miss anything I don't miss anything I have created I think I'm missing some notes well we're going to do something interesting here okay I mentioned encoded queries and you may or may not have seen encoded queries before I have a list of vehicles I've got 100 made up vehicles this is obviously demo data but I think it did pretty good day also on European like the 2015 list C or the seest East ma okay maybe they're all Italian cars I don't know but I've got a number of various fields in here this is just something I prepared earlier with some demo data and what I would like to do is go through and find all the records that match a criteria and then update them with a specific set of values so what I want what I'm going to show you first is how that can be done if I say show matching here you notice that the breadcrumbs this is this is sysadmin 101 or platform foundations whatever we're calling a fundamentals it creates a breadcrumb filter up here if I said like get me all of the ones that start with 2015 it will add that well you know what the display value is a calculated value and it's not gonna work there let's do the display value is calculated from the year okay so let's say the year is and year is greater than because it is a number you can actually see it's an integer with a comma in there greater than 2000 okay how many cars do we have that are active and greater than 2000 we have 14 so the reason I show you this simple filter is because if I right-click that and say copy query right there copy query you just click the last thing in the list and I'm going to put that over here it creates what we call an encoded query this is not a sequel statement but it will become one eventually depending on what database you have underneath the hood so active equals true and years greater than 2000 you can kind of read these things there's somewhat human readable and we showed how we can use these in a condition field which I will build for you in just a second the point of that is watch what happens when I click new because there is a piece of this argument that gets carried into the form piece of the URL that says I know you were looking for records with this condition on it therefore the next record I create will have that condition so my year did not come out to 2015 but active is true that's interesting oh you know what because it you can't do a greater than in there would have to be equals let's try that again your equals it would have to be an actual is to do an assignment can't do it a greater than equals starts with contains that kind of thing so let's say year is 2015 since I know there was a vehicle in there now if I click new year gets filled in with that value because it says this is what the value is I will help you this is how related lists work too you ever look at a related list let's say we're down on change requests and I have a change hopefully we'll get something nowhere this is an unrehearsed demo so anything could happen down on a related list notice that when I look at the I don't have changed tasks there they are changed tasks it says show me all the change tests that have this parent and when you click new it's carrying that in and saying ah I will automatically fill in the parent for you it's in that sis parm underscore query part of the argument so the Syst parm query the encoded query they're related they're very closely closely related the other thing that you might want to look at is if you've ever taken a look at templates and spell template right if I look at system was a system definition where is it where is it yeah a lot of stuff in here system definition templates I'll just take one that we already have I did click that will make sure that I did and find something on the change request template you take a record and you can create a template from a record it's capturing those fields in this values field no I can't edit this one because it's in global so let's quickly switch to global remember to switch back Charles uh still can't protected somehow but this field right here is storing field value pairs in and encoded query that's the important thing to note in fact if I take this I wish I could remember what that field is let's go to a different one that one might be special cuz it's a change let's look at one that's on incident in CID dent there we go major incident I want one I can edit mmm there we go the template field is of type template underscore value that's a field type that's not normally exposed and we have to do a little hack to get that but if I were to take what was it called it was it actually called template it's called template let's take this and tear it apart this is the reverse engineering part that I always talk about if I take the sis ID and you know what let's just take the whole URL because then the URL has the table on it I'm going to go to scripts background and save our template equals new glide record and I believe it's just called sis template there it is oops a pace took a little longer than I was comfortable here is the table name copy that put it up here a little shortcut sheet that I do he dug get but then quotes and get the society over here I want to see what's actually in there I know what's in there but I want you to see what's in there and then say get rid of that make that just a holy bit bigger for you there we go GS info T get value template Hey what's in there is look at this short description equals up caret caller ID equals JavaScript calling it does this look like an encoded query to you it is you would be right if you said yes impact is one urgency is one it's filling these out within a coded query so what can you do with one of these well you can use this template value field type to apply values to whatever you like just like you can put a condition field on records of your own you can put a template value field on records of your own whoo now we're getting powerful stuff because even more data-driven design for this so the DMV vehicle that I had before just has the DMV vehicle table with a hundred records in it and I am going to go and create some rules just like we did last episode I'm going to create some rules with a table and a condition filter and find records that match that condition and then apply a value to them in this case it's anything older than the year 2000 would be a collector item so I have this collector field make that a little smaller again I have a collector field which is currently false I don't think I have any that are true I don't know what it thinks it's doing here my browser plug-in got in the way true there are no vehicles with true but clearly we saw there was a 1950 out there so we know that there's vehicles older than that and I want to run this once a month once a year whatever I might do it on emissions standards there's a lot of things I can do to check for vehicles that match a condition then set values based on that template value field and it could be anything so this is where it gets fun let's go back to studio I have a lot of people that are chatting and making my watch buzz somewhere to try and ignore that as best as possible create application file table this is a very similar Oh before I do this I need to do one special thing and that is expose that template value field it's not visible by default if you go into the system dictionary in fact I will do this right now let's go down here to the field so I'm never gonna make the table yet but if I say set values that's what I'll call this field and the type template value doesn't show up it's not visible to the ordinary citizen there are 150 some different field types available in service now and they are all held in sis Glide object that list you're familiar with sis DB object that's where the table definitions are the field types are insist glide object and if I look at that list 150 different field types don't ask me what they're all about many of them are very very similar and I don't know the difference when to use one over the other so if you want to have a fun experiment go spelunking through here and see what's up you can usually find things that make sense like audio color there's boolean true/false it's labeled true/false but it's actually under the hood it's a boolean and if you go to any field and say show this checkbox field it'll say I am a boolean what we're looking for is template value and you can see it's currently not visible mmm that's why it won't show up as a choice I want to make it visible so one would think you come in here and say oh well I'm admin huh I can't check the visible box here's the hack workaround ok once again I'm going to copy the URL and I'm going to go to this background and get my table name which assist glide object as I said before take that and take the Society of this record with that in there and set the value get rid of that so I've got my record T dot active visible so unity divisible equals true true T dot update I just went right around that read-only form and I say the heck with that hey no more problem with this it is now we load the form reload the form hopefully I got the right one it is now visible which means I can go build my table so let's go build that table call it rule call DMV rule it doesn't extend anything I don't need a mobile module and I'm going to put it on the menu DMV so that's where it's going to end up just like before I'm going to start the same way I'm going to create a few fields one is called name because I want a name for this rule it's going to be my display value should I need to display it anywhere else I like last time I will make an active field of type true/false boolean and set that default to true I will make a table field although I could do since all the rules will be on the the DMV record I could just make this generic a static dependent remember the static dependent attribute from last time I'm not going to worry about that this time I'm going to put a table we'll hook this together as a table name the conditions this is a review of last time so I'm going to go through pretty quick will be a conditions field type not a condition string and watch this set values template value is now available for me to pick so there is my basic table of rules and when it matches what do I want to do with them Oh should have put it in an order yeah order would have been nice let's do that to order order order in the court integer and default value 100 sounds good update that let's go back to this and see where I've got my and I think studio may have created that in global I'm not sure maybe studio was civilized yorker default has been set let's go back to DMV oh i don't know if that came out right or not let's find out DMV rules okay I think I got it let's create a rule let's take a look at the form layout see how bad it came out yeah not optimal and let's configure this real quick just take 30 seconds clean up the floor make it easier because the condition should always go below the table the table can go up here it's a narrow field the order can go over there and the rest looks good that didn't even take 30 seconds I don't think reload much better okay collector vehicles now we still need to make that dependent let's save that let's make conditions dependent on tables so that we get the right fields when we select that default value we have to go to advanced again reviewing last time we're going to go to advanced and we're going to set a dependent field condition depends on table so that they're connected you pick a table the right fields show up and remember last time we had some attributes you can set them with the related list but I've had better success too in this readable readable equals true and show was a record counter broke out mm trying to remember we'll find out I think it was that if I save it and it doesn't match up in the related list it's gonna go what are you talking about I have one attribute I did not get that right so oh I spelled it wrong that's why so record count record count if I can't match it won't create the related list entries so try that fingers crossed going from memory no still didn't get it right let's try this show condition count that's what it is somebody out there is yelling at me and now I can fix that let's also take out the bad attribute take that out I'll remember one of these days that's right we have documentation right we just want doing an episode on something that's not documented let's go make a rule rules we already have one that's kind of made here let's check our conditions and whatnot so table is vehicle the order is there's our records we want to say active is true and year is less than 2000 if it's older than 20 years old it's a collector item now I do that my sect values are still empty something tells me I need to dependent there as well so let's go back to the dictionary rule table set values because it doesn't know what field values to pick it's doing the same thing as the condition field let's create the dependency there there's my dictionary entry for that make that dependent on table as well update it see if it shows up going from 3 years old memory to see if I can make this work and there they are I now have values what I'm going to do is simply set the collector field to true this is setting up a condition field so now I've got what I'm looking for and I've also got what I want to do with it when it's done if you've ever taken a look at my script las' scheduled jobs app from The Share Store might want to load this on your PDI don't load it and if it's it's it was an initial run at doing a scheduled job before flow designer came out with scheduled jobs that's I really recommend doing schedule jobs that way but it was a way of doing this it employed these exact concepts build a condition set some values because that's what a lot of scheduled jobs were doing look for approvals that were more than 30 days without being updated then set a value or trigger a notification or you know that kind of thing is very simple to do when you've got these couple of pieces in your in your arsenal of weapons that you can do this here's a condition now what we need is the logic to go behind there to say go look through these rules find the records that match and set the values well what do you know I have that already baked over here so let's go through this together go through the rule table get the active ones in fact let's set an order in here rule dot order order by order okay sort those out that way get the ones where the table is the DMV vehicle table which I believe I already did that was my one and only rule has the DMV vehicle table set values is not readable incidentally but condition is yeah that's the one then I'm going to get all the records and say hey I found so many rules that went with this not a problem for every rule that I find go get the vehicle record and that matches the condition here's where i'm using i'm not using glide filter to find out does this vehicle match any rules I'm taking the rules and matching vehicles so other way around from what I did last time a little bit different this is ad encoded query because the condition filter is my query I want all records that match that query active is true and vehicle is unless the year is less than 2000 okay easy to do but now I don't have to make up these rules I'm making a data driven set of rules to drive this script the script can come along later and go you know I don't use that collector rule anymore I use a new one deactivate make a new one same script works I'm not ever changing the script I'm changing the the rules that feed into it very very powerful stuff okay you've probably already looked ahead but for every vehicle I get here this is the magic that makes this all happen apply encoded query says take that encoded query from the set values field and put it on to the record this is I don't know why this isn't documented somewhere because I think it's really cool maybe it's because the template field isn't visible but this is exactly what template records do when you say hey I want to use this template value it takes the template fields and applies them to this new blank record and says there you are I've set it up for you the way the template said this is a template you now know a little bit more about the magic that happens in some of the out-of-the-box stuff and you can use that magic to power your own solutions later let's take this script and run it in scripts background I get really excited when I discovered this it was fun let's run this in the DMV app so that we don't run into any crazy stuff and run it does and it says I matched 40 records which we verified earlier all right you saw me create that filter one rule matched 40 vehicles matched and now if we look at our vehicles table we should see that the collector field on many of these is true which is awesome you're saying well Chuck why don't you just write a script to say look for vehicles have this condition and you know the sort of the inner half of that other script and set collector to true you would be making a script that is specific to that condition and set value field this is infinitely more flexible because I am never ever going to go back well sure that's probably pretty too strong of work I am less likely to go back to the script and make a change to the script whereas all of the logic all of the rules and the setting of the values is done here in the rules table I can come up with a lot more rules about users about see eyes about whatever I want now granted that script did say I only want the vehicles table so that would be my vehicle rules I could do other things with other with other scripts or take that one add query out that says only look where the table name is you decide what you want to do because I've got a very flexible set of conditions and set value fields they can how this script the only part that's restricting it to vehicles is this part right here on line five take that out and you can put users incidents see eyes loaner apps whatever you're looking for this becomes a way of doing this throw this into a schedule job to run nightly hourly whatever and you've got yourself an easy to do script now some of you who have looked ahead into flow designer may be saying hey wait a minute can't we use templates on some of the actions and steps the answer is yes and I'm going to get to that in a future episode I started looking into that go I know I've seen this why would you want to use that well because its script --less you don't have to write this part of it and it does effectively the same thing I will get to that in a future episode and very much looking forward to that so I think I've covered it all let me just look at my notes and the answer is yes again very easy way to create rules based on a condition set values with the template value field you do have to make the template value field from sis Glide object visible which is a one-time thing okay once you've done it you've done it and it's available to anyone who's making a table not that people are gonna use it all that often but for you serious power developers this is great stuff I have not been looking at the chat I've been looking at my notes and just which there would not have been a restriction on the tables all system could have been data-driven by applying these amazing concept what sort of restrictions are you talking about dhruv know that is dynamic inputs yes your talk that's you got it rip um that's what I was talking about from flow designer is dynamic no not necessarily dynamic inputs it's dynamic values let me see if I can find this on the docs real quick I was looking at docs I'll give you a little sneak peak in case you want to go ahead and look template values allow flow designer to dynamically set field values this is not dynamic inputs dynamic inputs is is doing introspection to to get what those are this is a little different this is when you're down here and you say template value I know you really can't see that that well so let's blow that up if you're doing a sub flow or an action you can use a template value input and say I want the template value from here still looking into exactly what the steps and processes are around that to make that happen but that's what I'm talking about for that a restriction on table licensing okay I'm gonna say it again I've said it a thousand times on your licensing licenses change okay I believe check with your account team template excuse me table based licensing was through 2020 I mean up until 2020 if you have a new purchase or you're renewing check with your account team because that may not be the case anymore again licenses change you've got to work with your account team to understand it's not all table table table table table table anymore obviously if you're working with integrations it's transactions so different things have different licenses so you may be watching this in the year 2027 thank you very much if you are that won't make any sense that's why I always say talk to your account team because licences change and they did change in 2020 so look for that so that's what I want to do is give you ideas give you hints give you thoughts and you can decide where you want to apply this I showed you a very simple example of going through and looking for collector vehicles and setting one field you could do a whole bunch of fields if you want depending on what's in that template it will take that in coded query string and put that on there that's going to do it for this episode I think I've got everything out there that I want to get I hope you got a lot out of it if you did don't forget to click the like that subscribe to notify that good stuff that you do on YouTube all the time and I will talk to you again on Thursday to show you how the loaner application would be rebuilt if I were going to rebuild it today which I am a very will do this is for my friends who don't have the ability to download the app from share and want to use some of the new concepts like flow designer that are not in the 2016 model they want to use mobile which are not in the 2016 model you kind of get the idea and what's behind all of this and why so join me for that same time 2:00 p.m. UTC Thursday June 4th weather and health permitting and we will see you there take care and have a wonderful day bye now [Music]
Info
Channel: ServiceNow - Now Community
Views: 1,437
Rating: 5 out of 5
Keywords:
Id: 6F8RDNbL4ug
Channel Id: undefined
Length: 35min 12sec (2112 seconds)
Published: Mon Jun 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.