Creating a unique number / ID in Omnis Studio

Nick Renders omnis1 at arcict.com
Fri Nov 18 16:00:47 UTC 2022


Hi guys,

Thanks for all the replies!

I don't know why I was so hesitant to use a global counter, but that does solve my problem.
I have a standard object class called oProperties (our own TMObjs, you might say ;-) so it makes sense to create a $nextID method there with a Class Variable to ensure no overlap.

Cheers,

Nick


On 18 Nov 2022, at 15:22, Doug Easterbrook via omnisdev-en wrote:

> hi Nick.
>
> I’m going to assume that there is a temporary number (never saves in a database) and local to a machine.    In other words, If you add a line to a list, you want a unique number in that list.    if you restart omnis, you can start again at 1, and there is no need to refer to that same number on another machine.
>
> I”m assuming tyhat, because #CT is unique to a machine and starts at zero if you restart the machine.
>
>
>
> if so, I’d suggest making a class variable (if the number can be unique to a window) or a task var if the number is to be unique to all lists in all windows.
>
>
> so.
>
> task var    ID  integer 64 bit initial Value 0
>
> and make a small method in your startup task called ‘$nextID’ that you can refer to in your $add
>
>
> do list.$add($ctask.$nextID,rest of variables)
>
>
> and $nextID is
>
> calculate ID as ID 1
> quit method  ID
>
>
>
> just replace any use of #CT with the  $ctask.$nextID function call
>
> that way you don’t need to change the variable type within your lists if you went with timestamps or UUID’s or what have you.  Your existing code should just work.
>
>
> it seems to me that all you are doing is serializing your lines in your list locally.
>
>
>
>
> Doug Easterbrook
> Arts Management Systems Ltd.
> mailto:doug at artsman.com
> http://www.artsman.com
> Phone (403) 650-1978
>
>> On Nov 18, 2022, at 5:38 AM, Nick Renders <omnis1 at arcict.com> wrote:
>>
>> Hi List,
>>
>> I was wondering if anyone had any good tips when it comes to creating unique numbers or IDs in Omnis?
>> For instance, to identify a specific row in a List variable whose number of lines is constantly changing (with $addbefore, $addafter, and $remove).
>>
>> I have been using #CT (number of ticks) but technology has caught up, and now there are situations with duplicate values because the calculations are done in the same 1/60th of a second.
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> Nick Renders
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com


More information about the omnisdev-en mailing list