logo

NJP

Introduction to ServiceNow System Property ServiceNow System Property Tips and Tricks with Demo

Import · Jul 25, 2022 · video

[Music] hi all and welcome back so in today's tutorial we'll be looking on some of the cheats on the system properties okay which may be useful for you in your day-to-day activities so as you know system property is a place where you can store some hardcoded values which you can use across multiple scripts okay so we use system property quite frequently right but while using system property a lot of people don't know how to make a maximum utilize utilization of the same so today we'll be looking on few of the cheats okay which i am using in my projects okay with respect to system properties and probably you can also use it in your own project so let's jump into it so as you can see on my screen this is my personal development instance and for today's tutorial we'll be using a background script don't drop me a comment why my background screen is looking black okay it's because of the plug-in which extension which i installed on my chrome which is a snug extension so let's let's for example so first of all how we face those oh first of all let's get some gathering information together some information so first of all system property gets stored in this is properties table if you are not aware about this uh then this is a table where you have to look for system properties okay now whenever we we want to pull any properties value right so the syntax for that is gs dot get property okay and inside curl insert on braces you can pass the property name for which you want to find the value so for example i have defined this property groups group string property so if i copy this out and if i paste this in the curly braces then ideally it should return the value for the same so i will give it as what i should variable equal to zero.property and then i will do this dot info and in that we will simply display this problem so if i run this out it gives the value which is stored in the script okay you can we can match it out so this is the value which we are getting but a lot of people don't know that if this property is empty right so as per the best practice we should have some default value set um for this property because this property will be you you will be used in your script throughout your script okay and if it has a null bro null value then it may break your code so as a best practice you should have some default value when some value doesn't exist so how exactly how generally we can do that we can do if prop if not drop okay if not drop then we can simply define some default value like then drop equal to abc okay something like this now what happens key if if i delete these values out right if i clear this value for this property let me do that so i will just clear this value out and i will save it and if we execute this property it will not return null instead of that it will return abc which can be a valid value right so if i get the gs dot info then prop okay and i'll just comment this out so let's see what result we get so now we get abc y abc because if i remove this out over there over here the prop has empty value so whenever it's empty you can you can you are replacing it with evc but you don't have to write so much of code right to get what you want okay you can simply define one additional attribute so i will just clone it out uh comment it out and with the property you can pass the second argument which will be a default value okay so what how exactly it works if the first argument property has empty return then it will consider the second argument as a default value so i will give def okay and now if i run this out so now you can see that as a default only it took dfy because this property has an empty value okay i will just restore this property out now in this property you can do multiple things okay you don't have to pass only single value all the time okay you can put a json a comma separate string and then you can play around it in your script for example let's take an example if we have defined json okay in this for in this particular example if you see i have defined a tradition first with the society of the first group and second is the society of second group and now i have to define a logic that i want to pull all the members who are belonging either to the first group or the second group so i i will not create two properties instead of that i have created one json with two keys first and second and now let's see how we can utilize this out in our code so the first and foremost thing we have pulled out the property okay i will just pass it out i will just remove the pillow thing i don't think it's required okay so for the first and foremost thing is i will pass it out this string because it gets stored in the string right so i'll pass it out into json json dot pass and then i will put this logic inside that okay and also i will change the property name so you want to use this property so i'll just copy this out and put it over here okay and now what the use case is we want to pull the group member which belongs to either of the group either first group or second group so how you can define the logic for the same so what you can do variable here remember equal to new glide record write record on which table i hope you know the answer so the group the table it says under user underscore cr member okay now we have done the query on this we will do the query so gr group member dot add query add query and in query i will give group because it's a backend name of a group in the server in that table group equal to now we have passed it out into js and write this particular thing so i can simply do drop dot first because i have stored that way out okay dot i will give and or query because i want to do the or operation or condition and i will give the second query which will be is crop dot second so what this code will do it will look for the members which have either part of group first or because we have added add or condition part of group second okay and then i will do gr member dot query and let's how we want to display it out so let's do while only file jr dot yeah group member dot next i want to display the name so it will be like what is the name in the table gr group member dot user i'm not pretty sure so if i execute it out say it okay i'm displaying over here right i'll just copy this out paste it over here and what i will do is just go to this table to see this packet name for title and the name so let's see how exactly it's stored so the backend name is user only so we will we can give this as i will copy this out from here control x to be ctrl a x dot get display value of what user and and let's see how exactly it looks so you can see all these are the members of this two group atm service level management horizons and look wilson and all right so this is how you can use the property which is stored at json now let's look into one more example so in this example what we'll be doing we'll be pulling the property of the use cases you can consider we want to use it as a hand query okay now we have looked into all so or let's go with the or query okay so we'll check with how how exactly we can extract it out of group members the similar use case only okay using a comma separate string okay so i've created one most property as you can see over here which we were using group string property so over here group name the similar same group name uh group c sides are stored in a comma separated format okay so now let's work on the same so over here how you can do we will go i will just first copy this property name we can go to the background script i will replace the property name out let's keep its default value as is okay but as now it's stored in the comma commercial testing we don't need this passing to the json right and we will have this group members only and now what you can do instead of this we will be replacing this out only so you can simply do group i'll just remove this entire thing out group and now we will use a in operator so group in now we have we already have a side is stored right in a copper substrate string we have to just pass that out so we have to just do the crop and it should return the same result okay so if i run this out i miss comma over here if i burn this out now as you can see it's returning the same result so in today's tutorial what we have seen with respect to property first of all how we can handle the exception where the property which you have defined has a null value or it's empty okay so you can set a default value then how you can store a property into a json format and then utilize that particular json into your script to extract some data and the third is like how you can store the property into string format comma separate string and how you can drive the operations around the same so this is all uh folder today's today if you have other use case where you uh which we can formulate okay using the uh properties properties okay our system properties okay please drop a comment on the scene till then stay safe stay happy and have a nice day thank you you

View original source

https://www.youtube.com/watch?v=B-VosyeN3Dw