logo

NJP

Simplifying ServiceNow Row Count: GlideRecord and GlideAggregate Explained

Import · May 08, 2023 · video

[Music] hi all and welcome back so in today's tutorial we'll try to answer a question okay which arise a lot of time a lot of people are asking this question out okay and whenever I am doing a quote review in my organization also I can see this kind of practice okay among a lot of developers and it's about when we want to do a count of rows okay into a database then what should we use so if you need to count rows you have two options the get through count method from Glide aggregate or get aggregate method and using count okay using Glide record to count rows can cause scalability issue as time grows over time okay because it returns each and every record with a query and then counts them for instance if you want to see incident with category software so what it will do it will pull all the records with all the attributes on that particular record and then it will start counting okay which may lead to Performance issue while Glide aggregate what it does it gets its Reserve from built-in database functionality which is much quicker and doesn't suffer from the scalability issue that light record does so let's see one example okay which can explain it out in a better way so what I will do which table have tons of data so let's take cmdb let's go CI dot list because then only we will be able to see the difference okay so how many records 2784 perfect and I will not add anything out okay let's let's query the entire table log and I will go to I will jump right to background script and what we'll be doing we'll be executing it with light record first and then right I get it and we'll see what is the difference between the execution type this is not a production environment this personal development instance so the data set is quite small and the difference of the execution time will also be small but when you go into actual environment this may vary and it may make a huge difference okay in the execution order so first of all we will go with the light record so new slide record we want to go with vegetable cm why cmdvca because it had tons of data see I will not add any query okay because I want to see the difference right so and I will do gr dot query okay and we can add if gr dot next then we can do simply TS dot info and info we can go to gr Dot get row count okay so this is all for this particular thing okay and if we run this out it took 50 seconds so for the execution if I run one more time let's see one more time so it took 44 seconds one more time so it took 55 seconds so on an average is taking around 50 seconds to get the row count for all the cas okay now let's try to do the same with glider create so what I will do variable t a foreign [Music] Glide record sorry not Glide aggregate and it will be on this and this code the table no query so I will do G8 Dot add aggregate what kind of activity do you want to add we want to count we'll do G8 dot query you must be thinking a lot of people ask me this question that we have to write a more code right one more line of code for this so it obviously doesn't make sense and you will be seeing it now okay so I've just done query and we can do if GA dot next in fact if it has any record then we want to display the count of the rows so you have seen that is the slide record took on average of 50 seconds let's try to get it for this GS dot info and we'll do GA dot get aggregate and I will just give account so we got the count as 2784. okay it should give the same count that's the first thing so if I run this out now so oh I did we want to do cmdca we got shocked again okay if I run this out it took 33 seconds okay let's do one more time 38 second 38 seconds so you can consider on average it's taking 36 seconds and when it comes to play degree it took around 50 seconds 51 seconds okay in this such a small set of users okay so you can imagine when the data set grows okay what difference will make okay what this difference will count okay so this is this is all for today in this tutorial I want to just showcase what is the best way to get the count okay whenever you want to do the row count kind of thing and from the example we understood that right aggregation is the best we also know the reason now okay why it's the best okay uh I hope this this tutorial was helpful to you and please subscribe to my channel so that you will get notified whenever a new video is coming on my YouTube channel okay till then stay safe stay happy and have a nice day thank you

View original source

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