Some ServiceNow records are easier to refer to if you add some kind of identifier or number, such as user groups (sys_user_group).
However, what happens if you have multiple instances where groups are being created, and you’d like to ensure that all user groups, no matter which instance they are created on, have unique sequential numbers/identifiers?
It’s as simple as creating a dynamic share for that table. However, the catch comes when you realize that, even after the sys_number_counter table is updated with the new group’s number, business rules aren’t triggered and thus the other instances aren't receiving the updated numbers and may end up creating different groups with the same number.
Here is where the dynamic share's after share script comes in handy. You can use that script section to define any activities that you want to take place after a dynamic share has completed, such as sharing the new number record in the sys_number_counter table.
First, you will need to create a dynamic share for the specific table (such as sys_user_group) you want to keep numbering in sync.
To replicate the sys_number_counter table and keep in sync numbering for a specific table, follow these steps:
First, create a dynamic share for the sys_number_counter table that has a filter condition on the table you want to keep sequential numbering such as sys_user_group. Note the sys_id of this dynamic share you create.
In the dynamic share for the table itself you are syncing (i.e. the dynamic share of the sys_user_group table), go to the after share script and add the following script:
where STEP_1_DYNAMIC_SHARE_SYS_ID is replaced with the sys_id of the dynamic share created in the previous step.