ServiceNow Scripting Best Practice Part 1
hello everyone so in today's video I am going to discuss about you so is now best practices so which we should we are following in order to maintain need and clean so it's not an instance for your customer so few best practices I am going to explain today and further you will be seeing other best practices in the coming videos so first fact best practice while writing the code you should always follow his comment your code so comments should be well-written and clear in your code okay especially on complicated sections it is good if you are mentioning the good comments so if you see the example here like where count is equal to zero if count is greater than max well so here if you see we have commented any slides variable so it is saying like what exactly the line is doing we are just initializing the variable and then at if is statement if you see check if we are overall limit so basically whatever we are doing if you will put the proper comment it will be easy to maintain the codes in future so it gives easy maintainability and if a new person or developer looks into the code it is easy for him to understand and if there is any issue in the code it can be easily resolved the next thing is wide spacing indentation in your code it is always good to use empty line and spaces to make code more readable then the format code button in ServiceNow syntax editor tool was is useful for adjusting the indentation so you can use ServiceNow a syntax editor tool over to you do the proper indentation and also it is good to use spaces between the lines so that code is more readable and other persons and even after sometime if you will look into your code itself it will be a good for you to understand okay the next thing is use descriptive variable and function names so many times we used to give just variables name XYZ ABC that is not good actually so always use a proper name for a variable definite definition and a function definition so when you are going to define a variable or a function it will be good if you define a good name or maybe give your comment to that function what exactly this function is doing so again back to row number two like commenting your code so meaningful names for functions and variable better indicate to reader the purpose of code okay so don't you just ABC XYZ add all those things if you see the example there the function name is Jay mentioned as delete if cancelled so it is the function name itself is saying like what exactly this function will do and then variable answer is equal to zero then state value it is saying like okay there is something happening with the state then glide record not a dot delete record so basically it's sort of properly indicate what exactly that variable is doing or the function is doing okay next avoid complex client record queries okay rather than creating a series of add query and add or condition a cause to obtain a result use the add encoded query to make the query easier to create and maintain so basically it is good if you avoid putting add very object dot add query object that carry maybe ten head queries you are putting so rather you can use add in coded query this generator encoded query using listview or write it down and this use atom coded query using the ad encoded query function okay for complex glide record queries it is easier to create a query string by generating encoded query string through a filter and using the string within coded query next we got is like use glide aggregate for the simple counting so if you need to get the row count you have two options get row count method from the glide record or glide aggregate using glide record two row counts can cause scalability issue as table grows over that time because it retrieves every record with query and then counts them so basically it doesn't impact you when you have less number of records in your table but by the time table will grow there could be lakhs of record to lakhs 10 lakhs maybe and at that time our ad get row count basically queries all those 10 lakhs records and then gets the count so basically it impacts the system however if you will use glide aggregate it will not impact so glider aggregate gets its result from built-in database functionality which is much quicker and doesn't suffer from a scalability issues that glide record does so if you will follow these some basic practices while writing your code in service now it is easy and to be easy to read and basically it doesn't impact system much and basically you are compliant to ServiceNow best practices ok so I hope you all will be following these best practices thank you for listening and watching the video I will be back with some more best practices video and videos on other topics as well you you
https://www.youtube.com/watch?v=hQviRBk9EDk