Problem with uniqueid( function. Why Morph choices change between datasheet and Form

Problem with uniqueid( function. Why Morph choices change between datasheet and Form?

I am trying to do the simplest of things.

I want to use the uniqueid( function to, well, make a unique ID for each record. Pan 6 was the ultimate in simplicity. Now I am stymied.

Approach 1 – Procedure

Field ID2
Formulafill uniqueid(“ID2”,“Anthem-”)

I get into field “ID2”
Execute Procedure above.
Results to not increment result. I end up with “Anthem-1” in all fields.

Approach 2 – Morph Statement in a form.
Only two choices.

I take Menu Field, Morph Field, then in the window I take default “Start with current Field”, and regardless of choice to add on I make I get nowhere.

Approach 3 – In datasheet view

I go to field ID2.
Execute Procedure.
I end up with “Anthem-1” in all fields.

I forgot where the bug listings are. If there is a bug with this function I’ll do a workaround with a sequence

I really have not comprehended why in a datasheet the Morph Menu choices are so limited. It is not intuitive why I must go to the datasheet to see more options. That is not a stopper because once you know it you can work around this idiosyncrasy.

Thanks for the assistance.

You might want to try

Field ID2
FormulaFill "Anthem-" + info("ServerRecordID")

That works and if I don’t use it agin for the Record ID it will not change.

In the documentation:
Note: The ID number is guaranteed to be unique, but is not guaranteed to be unchanging for all time. For example performing a new sharing generation will assign a new ID number to every record in the database.

I modified my “New Record” procedure and using the uniqueID( there does add a new record with a unique ID in the same format.

Is there a bug with the uniqueid( function?

This solves the problem for me Dave. Thanks.

Once again you are a member of the Calvary, wearing a White Hat!

I tried a slightly different formulafill using the seq() function and then tried adding a new record and using the uniqueid() fuction to populate the new record.

Field ID2
formulafill "Anthem-"+seq()
addrecord
ID2= uniqueid("ID2","Anthem-")

Here is the screen shot showing the initial 12 records along with the newly added record in the ID2 field:

Thanks Gary.

One compromise is that if I unselect the records containing “Anthem-” and execute the procedure again for records without value for ID2 the sequence again starts at one and sequences.

So I end up with duplicate record IDs.

Thanks for the help. I can work around that.

George

That uniqueid() doesn’t work in a formulafill is a known issue:

You could select the empty ID2 records and loop through them to assign unique values and then re-select all the records at the end. Using uniqueid( in a loop will work properly and check all records whether selected or not to find the next unique value with no duplicates.

field ID2
select sizeof(ID2)=0
firstrecord
loop
    ID2= uniqueid("ID2","Anthem-")
    stoploopif info("eof")
    downrecord
endloop
selectall

What is your actual reason for wanting a unique ID for each record? What are you going to do with this ID?

Over 30 years ago, the uniqueid( function was invented as part of the synchronization capability of Power Team (if any of you remember that). It’s no longer needed for that - instead for multi computer applications you should use Panorama Server. So the original purpose of this function no longer exists, it’s become somewhat of an orphan with no “official” purpose.

If you just need a unique ID, I would recommend that you don’t need a field, just use the info(“serverrecordid”) function. For single user databases, this is guaranteed to be a unique, unchanging value.

If this is a shared database, then the number is still guaranteed to be unique, but it will change when there is a new generation. So you wouldn’t want to use this number as a key (i.e. put the unique value in another record to use as a link).

Which comes back to my original quesion – why do you want a unique value? This isn’t a trick question - based on the answer I can suggest the best solution.

One reason is that I have always created a unique ID. For at least 3 decades. Sort of engrained into my methodology.

What do I use it for??

I have a client database and a project database. I could have several projects with one particular client and I want to link to them for viewing or editing.

In creating an invoice, for example, I put the customer ID in the particular invoice and then I fill out the address detail, contact name, etc. in the form.

A price list for assemblies.

Think of it like a “Car” with options for engine type and tires. Not only do we have several options for the engine type and the tires, all independent, but the price depends on the quantity bought.

In the “Car” record are fields that list options. Each option has its own unique ID and the cost of that option is a function of the number of “Cars” purchased. I create a price list that does all the math and sums them up, by quantity. It reality it is not a car but an electromechanical actuator with options.

That is the way that I have done it. I don’t know how else to do it. In my mind I need a unique ID for a given record that does not change.

Thanks Jim. I know that it was not a trick question. Not your style!

I would recommend that you simply use the Panorama feature for creating a unique record number – set the field default to +. Panorama will automatically create unique numbers as each record is created.

Thanks Jim.

I can see now that the way I have been doing it is redundant since a unique ID can be “baked in”, so to speak.