What are the issues with sys_id being hardcoded?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:09 AM
1.
What are the actual issues with sys_id being hardcoded in a script?
I know people say to make use of system property. but in sys property also we enter sys_id.. then whats the issue if I directly hardcode in script?
PS - I know that when that sys_id is hardcoded in multiple scripts them system property is helpful so that changing here will reflect everywhere. Apart from this, are there any other issues?
2. Even ServiceNow OOB also had hardcoded in many places. Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:20 AM - edited 04-04-2024 01:22 AM
Hi @Suggy
There's none. I too have never encountered any issue after hardcoding it in the scripts. Even ServiceNow has hardcoded it at most of the places. But you need to make sure that you've kept it same across the instances.
As far as best practices are considered- Hard coding sys_ids is not recommended, as they may not be the same between instances. Instead, try looking up a value by reference or by creating a property and retrieving the value with gs. getProperty(). Hard-coding group, user, or other names often leads to problems when an organizational change occurs.
All the scripting related best practices are listed here-
Please mark my answer helpful and correct.
Regards,
Amit