Ask the Expert

Generate a Windows Globally Unique Identifier

We have an application that uses a database for each state -- this is for the convenience of the users. However, for reporting purposes, we move everything into a single database. This creates a huge drain on server resources as we remove and add documents -- the process is laborious simply because we want to ensure we don't end up with duplicate UNIDs, no matter how remote the chance.

We're looking into other ways to generate unique keys, and we'd like to know if there's a way via LotusScript to generate a Windows Globally Unique Identifier (GUID). I've done some searching and people only talk about them, not how to generate them on the fly. Can you help?

I once created a script routine that created a time stamp using 32 characters and then verified the existing key didn't exist. If it did, then it added an additional digit. Probably the easiest way to create unique IDs is to use the @Unique function to generate a part of a key, a database identifier as prefix and then append an 'a' or '0.' Verify the key doesn't exist in the current database, if it does already exist, then increment the last digit and verify again.

So, IF I created a document, @Unique would generate a key like BMAY-66RH28, where the first segment was generated from my userID and the last part is related to date and time. IF the keys are all generated by an agent and signed by the same ID, the first part is not really relative. Start with a database, or a state identifier, PA, add the timestamp part of @Unique, 66RH28 and an initial differentiator -- 0 to get a possible key of PA-66RH28-0. Check if a document exists with that key, if it does increment the differentiator by one and check again.

In some applications, we change the position of the differentiator and database identifier so that the 0 doesn't always appear at the end of the key. So possible variations of the same unique identifier, PA-66RH28-0, in different formats could be PA66RH280, PA-066RH28, 66RH280PA and 0PA66RH280.

Do you have comments on this Ask the Expert question and response? Let us know.

This was first published in November 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: