logo

NJP

Using related list queries in scripts and other applications

Import · Aug 22, 2022 · video

[Music] hey hello everyone uh whosoever is watching online thanks for joining so uh without any without wasting any time today we'll just jump into our topic today so today i've got a very interesting uh thing to talk about with you guys using related list queries uh and scripts and other applications so i'll just start off sharing my screen and you know talk through other items there on so you know many many times what happens is we do get a requirement and when we have to you know update some bulk records on based on some conditions or you know repair a particular sla or we want to check a particular cmdbci record and do something with the related records that the ci has got so in a in a similar fashion today i'll be you know demonstrating a use case that where you know a very long script can be turned into few lines of code using related list conditions now starting off so first thing we have got a list of instance over here and what we want to do is we want to so you know we want to uh check the incidents which are not having any sl attached to them right now to do this but what we can do is we can also build out a report but we just just don't want to you know check if there are any sls attached to it we want to repair the slas as well on the records now if there are you know incidents in bulk on a particular in uh on a particular instance what we might have to do there are like 10 000 20 000 or whatever records that we have got with us so in this case we will have to write down a fixed script or you know execute a particular script now if we are going to execute a particular script for example this one right where i the first thing that we'll have to do i want to check only priority one incidents that are currently active and then see look for the incidents which don't have any slas attached to it attached to it with this particular filter so as you can see this is the script that i bought here so the first thing that i'm doing is i'm looking up you know doing a query for priority or instance and doing active query and whatever comes out to me i'm then looking at at a task asset table and you know then again passing on the uh incident society current incident society over there and looking out for the incidents uh the count of the incidents uh which don't have any sla attached to it so now just for demonstrating purposes i am having count here but the other thing that we can also do is we can do anything like if like for example again you know if we're looking at the sls i want to repair the slash or you know attach the slash to this particular instant and i make sure that the slas are attached to every incident in the instance so this is one way of doing it you know a query glide record inside a glide record now there's another way that we can do uh this query so you know using the related list conditions so as you all know if i walk on to the incidents while this is opening up let's also hopefully my laptop doesn't die today let's see still have to start using my mac all right so we have got two slas attached to it and we have got this related list so we what we will be doing is instead of doing a you know client record uh query we will just be doing glide record once and we will be having a encoded query using related list conditions now how do you get to those related list condition there are a couple of ways of doing it first one is i can go on to the reports module right right and click on create a report and if there are any questions on the chat i'm alone today i'll be having a look at it later so i'll be having giving it the name incidents without an sla i'm doing a table rules increment yep and so as our first script i'll be selecting priority one and active true right so active and ready yes so if i execute this it comes out with around 27 incidents right now we want to check if it has got an sla attached to it or not so what we can do is we we've got related less condition than this and we'll be having so we are looking at engine without an sla which will be related list condition equal to zero and we'll be selecting sla so sl task sla related list and we don't need any conditions over there we'll just execute it once that is done we have got around 18 incidents that are not having an sld now we i can probably do anything i want uh with uh i want to repair the slash the attachment slash to this or it can be anything right the use case can be anything but right now we're talking about uh you know having slash attached to those incidents which are not having any slash attached to them so we've got a report and it is showing us 80 incidents which is perfectly fine so i'll save this and i will go to save now once this is done i will go to only executing both these scripts later on to show the exact same result is coming out of both of of both the scripts now we have got incident without an sla we'll open it now we do have the filter here but again as you can see it is just having active is true priority is critical we don't have the related list conditions shown up here now the first way you can do you know get out the relate the query that we want to apply to our script is do a right click show xml and enter so once you can get there so filter we do have the query over here which is active through priority one and we also have our related list query so we will just take a copy of this control c and we will close this now we will go back to our script so i've got the query that i want to apply in the script this is the query and it's same as above so i'll just remove it for now now we we will apply we will just do uh you know glide record for incident table and then apply encoded query where active is true priority is one and related is this condition there is no sla record found with that related to that particular incident once we execute this query so again we can do anything here we can repair the sla we can update work nodes whatever we can probably connect like you know even whatever you want so there can be anything that you want to do so we right now i'm getting the count of these particular incidents so i execute this it comes up as uh incident without sla18 now as you can see it's just i think eight to nine lines of code now if i go to the app script without related list conditions where we have again we are querying priority one active true and while the incidents are being you know fetched so we are again doing another uh glide record and where we are passing the instances id and i'm getting the count of total incidents and incidents so if no sla record is found against them i am doing account plus plus so count sla plus plus and i've got so if i execute this it says that uh total incident 27 incident without tesla rating so you can you can see the difference here you know we don't have to go down the path of writing at least these must these many lines of code we can just get this done in a single line which is this and i personally really loved it when i came across this recently you know and i did sla repair on about 25 000 ritm records so which was again you know a challenge to get it done uh so this this this is something that we can use and this is how we can use the relatedness query in the scripts and now the you know creating a report and going on to show xml and getting out the filter so this is one way of getting the related query now the other way that we can do is we if you you've got as in utility installed uh and and if you double click on a particular field you know it comes out but here it's not coming out let's probably leave this one and so what we can do is we can go to the report the actual report that we created and if we open this condition builder double click on it we will have this query over there as well so that's another easy way without you know going to the actual report record we can directly click on the uh condition uh and uh you know copy the uh the conditions that the report has got and which will include the related query conditions as well so but again for this one you need sn utils installed on your uh range on your chrome uh or the browser that you're using now in a similar fashion if you have got this particular query right and you want to apply the same you don't want to execute a script but you want to check some particular records in a list view right so i've got the incident list view over here and how many incidents are there without and without slas right so again this is a use case of have you know sn utils so if you double click on the filter right so if you double click on the filter filter condition uh you can here and you've got the the query from uh your report or you know where's however you got it you can apply the same and you know it will be applied and you know it will be filtered out so same way you can you know you can probably use these uh related lists queries in scripts and you know doing filters in list list view and it is applicable to all the uh applications and you know many times it another good use case of using these would be cmdb where there are there can be thousands of recorded related to a particular ci or you know and slas is obviously there so there can be we want to check if a particular maybe change record is having any uh outages attached to it so that can be enough it can be any table right so we just we are just playing around with the related list here so we just checking that if it has got any related records and we want to do something about it so hope this helped and i'll probably switch on to the questions if you've got anything in the chat i understand any question guys just you know feel free to ask probably stick forever nice nice open all good i'm trying to find something new right hey honey do you want to join like let me probably do something how do i invite someone [Music] nine people are watching us okay alrighty uh that's all that i had today uh hope this was you know something new and that you came across and it will help probably writing scripts if you are doing so and you know fix scripts and doing some bulk updates to record our particular table and yeah all right thank you everyone if there is nothing else i will probably right thank you demo thank you guys see you next time

View original source

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