logo

NJP

GlideRecord get - Did You Know

Import · Jan 13, 2023 · video

foreign as much as I love talking about low code capabilities on the platform I realize there are times when we need to write some JavaScript here's a common situation we all face getting a single record using the Glide record class well did you know that there's a method to do that so that we don't have to write ad query query and next it's called get and it's really handy for more than just sis IDs let's take a look now if we didn't know about get we might use a script something like this to retrieve a record based on its sysid we'd first use add query as a filter to get the record that matches a particular society and then use Query to submit our query to the database and use that if casegr.next to check if there's a record to get it would work and it's not wrong but there's a shorter and somewhat clearer way to do this a script like this does the same thing to try and get a record with the given sysid and if it fails it returns a null and skips the inside of that if block pretty nice right but wait there's more did you know get can accept two parameters check it out this version of get uses the first parameter as a column name and the second as a value it's trying to get the record on our table where number is CS triple zero one double o seven so Chuck you ask what happens if I use get where multiple records match like this so glad you asked I reply as suspected there are potentially lots of records with the value of Priority One in our table the short answer is we get the first one the database decides to pick and in most cases this isn't a good policy because we're not sure if it's the exact record we want however this could be exactly what we want if we simply want to check if there are any records with Priority One although I might suggest looking at using Glide aggregate if all we want to do is Count records but that's another video for another time it might even be that our priority column is using that unique field that I talked about a couple of videos ago so there are no duplicate records in that case we're okay we'll either get that one record back with this value or we'll get nothing like the other examples we've seen well there we go Glide records get method can not only shorten up your code it can enable us to do a few other things when we just need to grab one quick record based on a field value that's all for this time don't forget if you've got a tip about the platform and app or capability share it with the world and don't forget to use the hashtag servicenowdyk to be part of the community I'll be back soon with another servicenow Dyk thanks for watching [Music]

View original source

https://www.youtube.com/watch?v=0UNITC4CX7A