What are the issues with sys_id being hardcoded?

Suggy
Giga Sage

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?

Suggy_0-1712217723470.png

 

1 REPLY 1

Amit Pandey
Kilo Sage

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-

 

https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/scripting_technical_bes...

 

Please mark my answer helpful and correct. 

 

Regards,

Amit