Skip to content

How to replicate the sys_number_counter table

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #6621
    Zak Cole
    Participant

    Some records are easier to refer to if you add some kind of identifier or number – for example, user groups (Read more on ServiceNow’s numbering system here)

    However, what happens if you have multiple instances where groups are being created, and you’d like to ensure that all groups, no matter which instance they are created on, have sequential group identifiers?

    It’s as simple as creating a dynamic share for that table. However, the catch comes when you realise that, even after the sys_number_counter table is updated with the new group’s number, business rules aren’t triggered!

    Here is where the ‘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. Like… Sharing the new number record on the sys_number_counter table!

    Please see the below code as an example and make sure to use your own share’s sys_id:

    var dynShareSysId = '5da7ea644f2123005b0c22788310c7fd';
    if (psp_action == 'insert'){  //We only want inserts to replicate
    	var ngr = new GlideRecord('sys_number_counter');
    	ngr.addQuery('table', 'sys_user_group');
    	ngr.query();
    	if (ngr.next()) {
    		var pspR = new PerspectiumReplicator();
    		pspR.shareRecord(ngr, ngr.getTableName(), 'bulk', dynShareSysId);
    	}
    }
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.