How to generate sequential numbers?

DarkAvenger
Kilo Expert

Hi all

 

I got this situation that I need to generate unique ID numbers for web services calls made to an external vendors system.

 

The calls are made with data from the Incident table. Each call needs to have a unique ID that does not match any past number. Also theoretically the system will be making multiple calls for every Incident record that matches specific requirements and because of this it is not possible to use the Incident number or sys_id as the unique ID.

 

I looked into adding a record into the Number Maintenance table but that table only allows one record per table. Being that it already had a record for the Incident table, I was not able to add a second one tied to that table (my thought was to make these web service calls from a Business Rule tied to the Incident table).

 

Although I could e.g. create a new table for these numbers, there might be simpler ways to accomplish this and thus I wanted to know how others have solved this issue?

 

How would you generate ID numbers in this case?

 

Thanks

4 REPLIES 4

Michael Kaufman
Giga Guru

I think new table method you mentioned is the way to go.   The table would contain the incident number and the unique number of the webservice call.   You could use getNextObjNumberPadded(); call to generate a number for each webservice request.  



Maybe the external vendor system has a webservice response that you can use instead for the unique number too.



Mike


Thank you mkaufman.



I had went with obtaining the amount of milliseconds since 01-01-1970 from the "sys_updated_on" field and converting this to a string.



Sort of like this:


var iUniq = new GlideDateTime(current.sys_updated_on);


iUniq = iUniq.getNumericValue().toString();



This seems to work fine for now but if I for some reason need to use the Number Maintenance table (e.g. some of the web service calls may not be tied to an update, I am not fully sure about this yet) then I might go ahead with adding a separate table for this. This vendor does not have a web service method through which they would provide a number.


eican
Kilo Guru

You could copy the way how watermarks are generated


Ravish Shetty
Tera Guru

Incase if you did not get a solution yet (if you did then please share), i would suggest that you define a new property for this purpose.



Example:


property name: custom.sequential.number



Now if you want to get the unique number then do this:



var unique_number = parseInt(gs.getProperty ('custom.sequential.number'));


gs.setProperty ('custom.sequential.number',(unique_number + 1));



This is one of the way and causes cache flush so i am not sure if its recommended.


Alternatively you can have a custom utlity table (or if there is already an existing one) in which you can store your number and increment it during each webservice call.