- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:03 AM
Hi All,
I want to know what is hard coding in scripting. Could you please give me different examples. And if our code is hard coded what is the problem.? And how to avoid using hard coding.
Thanks in advance 🙂
Solved! Go to Solution.
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 05:41 AM
under 'value' field.
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:10 AM
Hello Umar ,
lets take an example where you want to get on incident record and you are querying with sys_id directly so that you can pick up your record easily like below
var gr = new GlideRecord('incident');
gr.get('93ee0b121b1dd9900b8a9979b04bcb88'); --> Now this is called hard coding of sys_id which is not recommended because its easy to change any letter or number in the sys_id in future which fails your script
so as a bast practice we will store this sys_id in a system property and we call system property here so that its safe and failing of script has less chances
var gr = new GlideRecord('incident');
gr.get(gs.getProperty('your property name containing sys_id'));
Hope this helps
please mark my answer correct if it helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:11 AM
Hi Umar,
Please see below example
Do Not Use Hard-Coded Values
Avoid using hard-coded values in scripts, as they can lead to unpredictable results and can be difficult to track down later. 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. For example, assume you assign a value of Service Desk to the script variable for a group name:
var taskID = '26c811f06075388068d07268c841dcd0';
var groupName = 'Service Desk';
The script will not function as expected when the group name changes from Service Desk to Help Desk. Instead, use a property:
var taskID = gs.getProperty('acme.default.task');
var groupName = gs.getProperty('acme.group.name');
Also consider the following example in which a workflow needs an approval from the IT director of Acme Corp. Sara, the former IT director, has been replaced by Dale. See why the initial approach of hard-coding Sara's user information is not preferable.
Initial Approach:
- Create a user approval activity for Sara.
- When Dale becomes the new IT director, update the workflow.
Better Approach:
This method eliminates the need to add hard-coded data in the workflow.
- Create a group, IT Director, and make Sara a member.
- Use the Group Approval Activity.
- When Dale becomes the new IT director, simply update the group membership instead of the workflow.
Hope it helps!!
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 03:57 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 05:41 AM
under 'value' field.
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg