Jump to content

Reset Script for Unique Alphanumeric ID


This topic is 2526 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Each record I create has a unique ID. When I create an new record that ID automatically increases by increments of 1.

 

When I create a record in error, and delete the errant record, I need to reset the next ID so it retains a linear progression.

 

I have created a simple script that allows me to reset the unique ID of the next record

 

Go to Record/Request/Page [Last]

Set Next Serial Value [Visit::Statement No.; Max (Visit::Statement No.) + 1]

 

The above script works, except for one thing:  I want the reset ID to read: "00000X" or "M0000X".

 

In each case the reset value increases to the next value, as required, however the FULL ID is ignored. For example "00005" when reset becomes "5". "M00005" when reset becomes "5".

 

How do I modify the above script to maintain the original ID configuration:  "00000X"  or M0000X"

 

Thanks

Link to comment
Share on other sites

I want the reset ID to read: "00000X" or "M0000X".

 

The "or" part doesn't make sense here; you cannot be ambivalent when giving instructions to a computer. Assuming you want the same format as in the last record (which should be the format defined for the field), try:

 

Show All Records
Unsort Records
Go to Record/Request/Page [Last]
Set Next Serial Value [Visit::Statement No.; SerialIncrement ( Visit::Statement No. ; 1 )]

 

A better practice, IMHO, would be to set the serial number field to generate on commit, and make sure you do not commit newly created records unless and until you really want them (e.g. by using a "Post" button, followed by a "Are you sure?" confirm dialog).

 

 

---

P.S. Please update your profile to reflect your version and OS.

Link to comment
Share on other sites

Sorry about the confusion regarding "or" ... I was referring to using the script in 2 separate instances... so I wanted a script that was flexible enough to allow either instance. 

 

The script you provided works great.

 

I wrote this database in 1997, without any prior knowledge of FMP, and continually update its functions. I am not a professional, and understand only the surface of what I am working with. I am the only user... It works for me... but it is not as refined as I would like. I would very much like to add the "commit" function to ID entry.  It definitely sounds like a better practice.

 

Can you show me how you would write that script?

 

Thanks

 

Mark

Link to comment
Share on other sites

The script itself is trivial:

Show Custom Dialog [ "Are you sure ..." ]
If [ Get ( LastMessageChoice ) = 1 ]
  Commit Records
End If

The non-trivial part is preventing accidental committing. For this, deselect the "Save record changes automatically" option in Layout Setup. However, doing (only) this will result in an annoying dialog being displayed whenever you click outside of any field. A relatively easy workaround is to place a large empty web viewer object in the background.

Link to comment
Share on other sites

On a slightly different note:

 


When I create a record in error, and delete the errant record, I need to reset the next ID so it retains a linear progression.

 

Why? How does it matter if the IDs are not in exact linear sequence?

 

Cheers

Webko

Link to comment
Share on other sites

Thanks for help with script... Works beautifully.

Regarding...

 

Why? How does it matter if the IDs are not in exact linear sequence?

I just like a clean database with clean reports. Is there another way to keep things orderly?

Link to comment
Share on other sites

How does it matter if the IDs are not in exact linear sequence?

 

I have some clients that are obligated to number certain financial documents (Invoices, Receipts, etc.) strictly sequentially by their tax authorities.

 

 

I just like a clean database with clean reports. Is there another way to keep things orderly?

 

Why, yes. If you don't have to keep sequential IDs, you can just set-and-forget them. For reports, use a summary field to count your items. Or just the record number symbol.

Link to comment
Share on other sites

This topic is 2526 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Similar Content

    • By bgscott
      I have a field, item ID, set to auto enter a serial number and validation set to not empty and unique.  If the serial number entered is not unique I do not get an error message when exiting the item ID field.  If I turn off auto enter serial number and manually enter a non unique item ID, I do get an error message when I exit the field.
      With auto enter a serial number turned on I only get the non unique error message when I commit the record.  I would like to get the error message when exiting the field when auto enter a serial number is turned on
      Any suggestions?
    • By jbw
      Hi - OMG, I am at the end of my tether on this. Any help would be so much appreciated. It's probably an easy fix. Basically, I have a big database with a Company table and various linked tables (contacts, products etc.). It works well, and all the data is already populated, BUT I did a dumb thing on set up: the table relationship match field is the Company Name, which means if the company changes its name I cannot change the Company Name field as it is a match field (the portals on Company table layout just go blank as there is no match). I did a workaround (two name fields), but what I really need to do is have a unique ID (auto enter serial number) for the company table and just link it to the other tables.
      So I created a unique Company ID in the Company table, and have popiulated this with an auto enter serial number - fine -  and then as per FMP's website I add a "Company ID" field to the Contacts table. But it does not populate or link. And I see in the forums/online that this works for NEW records I add. But I have 3000 existing companies in the database. I have tried several things but I just cannot get it to work. The Contacts portal on my Companies layout never displays anything. When I view Contacts in table layout, Company ID is always blank.
      Thanks in advance for any help.
    • By Capt JB
      Guys,
       
      I've no programming background, so I am asking for help  . 
       
      I have a text field with an automated serial number of three digits by increment of 1. This serial is part of an ID number that includes the current date.
      I am trying to have this serial returned to 001 at midnight, meaning that every single day the serial starts at 001 up to maximum of 999.
      My problem is I cannot have the serial reset to 001, unless I do it manually.
      Any help will be very much appreciated
       
      If there is a link available so I can learn basic programming instead of sucking knowledge, it will be very much appreciated too, and I would feel better..  TIA
       
       
    • By Jed69
      I am trying to create an autogenerated Id number for an invoice but this number must be prefixed by the year for example 2012/1 however at the start of each new year these number need to go back to 1 so for example the first invoice next year will be numbered 2013/1. can anyone suggest the best way for this to be done.

      John
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.