Gliderecord object as parameter to function. Good or bad?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 01:27 PM
Hi all,
is it good or bad practice to pass a gliderecord object to a function?
if i am not wrong servicenow does it in script like business rules with current and previous
thanks in advance
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 01:29 PM
I don't think anyone can just say that passing a GlideRecord object is bad. It's more about what you're using it for and if you really need to pass the whole object. If the script you're building doesn't need the entire object, why pass it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 01:32 PM
It's not a bad practice as it is used that way in many of OOB scripts. However, as a developer, you can determine whether to pass the entire GlideRecord object for the given scenario. If your function is going to access only a single field's data from the entire Gliderecord, then you need not pass the entire GlideRecord.
** Mark this response as accepted answer/helpful, based on impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 02:02 PM
SN does it so don't think it's a bad practice but how it's being applied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 06:06 PM
Hello,
It is all about where you are using.
Passing glide record is not something bad most of the times.
But remember when you pass you are passing it is passed by reference, so if the gliderecord is altered on your function it would be altered in the main execution stream too, check the below example
In this I am passing clide record to my function and setting a exactly opposite query condition than from my main execution stream so the result I got is nothing.
Imagine the same situation in a script include where you have glide record is passed from one function and which is altered by another on extended script included whereas your other function has a logic which could get messed up by this.
To conclude: Yes can be passed but know the risk and use it in a place where your logic can't be inherited.
Regards,
Sateesh Kumar Devadoss.