kristymerri
Administrator

 

As ServiceNow developers, we've all seen the temptation to drop a sys_id directly into a business rule for assignment logic. It works... until it doesn’t.

 

In this episode of Did You Know: Best Practices, Shamma Negi walks us through the dangers of hardcoding sys_ids in your logic. Specifically, she demonstrates how code that assigns groups based on sys_ids can fail when moved across environments because those IDs may not exist in the target instance.

 

Instead of relying on brittle IDs, Shamma shows how to use Assignment Rules, a powerful out-of-the-box feature in ServiceNow. She walks us through a demo where an incident gets automatically assigned to a database group when the communication channel is Chat, using only names and conditions, no hardcoded IDs.

 

But the learning doesn’t stop there. We wrap up with four best practices:

  1. Use System Properties for sys_ids if absolutely necessary. This makes your config more portable.

  2. Leverage Decision Tables for complex assignment logic that evolves over time. They’re visual, scalable, and maintainable.

  3. Include Key Records in Update Sets or seed data to ensure consistency of critical configuration across instances.

  4. Run Instance Scans regularly. These help catch hardcoded references or other no-no's before promoting to production.

Whether you're building new apps or maintaining legacy ones, this episode is a quick but critical reminder: clean logic is portable logic.

 

If you’ve got a clever trick or a lesson learned from the trenches, we’d love to hear it! Drop it in the comments or tag us in the community!

4 Comments
Dr Atul G- LNG
Tera Patron

@Shamma Negi Hureee..finally 

wclim
Kilo Sage

Just wondering out loud - in assignment rules, when setting a User or Group record in the rule, doesn't the xml update of the assignment rule gets recorded with the sys_id of the user or group in your update set?

 

Doesn't that mean that if the assignment rule is pushed to another target instance via update sets or other means, the same sys_id in the config remains. 

And the same issue might remain where these sys_ids may not be in your target instance.

 

Would a better option here be to make sure the sys_ids of groups are the same between environments by doing xml exports and imports of group records to keep sys_ids in sync?

 

Open for alternative views

Mikael Karlsson
Mega Sage

@wclim exactly. Since the assignment rules are hopefully created in subprod, once they are deployed to prod it's basically vulnerable to the same issue as the hardcoded sys_ids. If the video recommends configuring this stuff in prod as admin i would argue it's 100x worse than using sys_ids in simple scripts.

 

But this is one of the first issues faced by new ServiceNow customers so all have definitely put some kind of process around it. In most cases i would believe that production is the single source of truth. Users and groups and other important masterdata must be "born" there via imports or similar and in one way or another reach subprod (cloning, sync, export/import). Otherwise it wouldn't be possible to configure approval processes, location specific behaviour etc if each instance had different sys_ids for important masterdata records.

Heiko Bllr
Tera Guru

Hi,

In high regulated environments you will not have PROD user records in Sub PROD so you need to give up on the idea to configure individual users for approvals, assignment rules etc.

Stick to groups instead and make sure they are in synch (sys_id) across your instances.

HTH,

Heiko