Global fields were designed to work this way. Every user get's a "virtual copy" of the global field and changes made to a global field are not seen by other users.
Your scripted work around is not safe as you have discovered. If two users run the script at nearly the same time, both can get exactly the same value and you get duplicate values.
What you should do with your invoice number if open field options and define the field to auto-enter the serial number. You then do not need a global field nor do you need a script.
For more on globals and hosted files: http://help.filemaker.com/app/answers/detail/a_id/3604/kw/global
I read about these copied global fields and I though there is a workaround or some other type of field.
I can't use a serial number as a unique ID for invoice number because the Invoice in my software can be 3 types, and each type should have the unique ID incremented, not random, this is how the law states it so I can have a total number of invoices upon inspection. Therefore if I create and delete one the serial number will skip it.
Is there any field declared only once that even if the file is shared ?
If not, how could I create such thing in order for multiple people to use one field and increment a number depending on the invoice type :(
Thank you for your time Phil.
You still need to use the auto-entered serial number. Once you assign such a value to an invoice, you do not ever delete it. If the need to delete it arises, mark it as "void" and zero out any fields that would other wise report a currency value for the invoice. This is just like printed receipts and allows you to generate the needed values from the far simpler and safer auto-entered serial number feature.
(And it is possible to assign such a serial number to a field "on demand" with a bit of creative design work.)
Do you know of any plugin that could do what I'm asking for. Either as global field or variable, any way.
You can get the total number of invoices "on inspection" without having a perfect sequence of ID's. I still think you can get an auto-entered serial number to do what you need and that will not require a plug in.
What do you mean "on inspection", I'm still relatively new to filemaker.
Please help me with a solution on using auto-entered serial numbers because I can't come with one. As I said I have to invoices types, and an invoice can be deleted and also switch type, making it void doesn't help because I have to have a valid invoice for each invoice ID.
I'm sorry that I keep asking this questions, but my problem still persists :(.
"on Inspection" is a quote from your post. What do YOU mean by that phrase?
And what does the invoice type have to do with the invoice number? Why does a different type of invoice require a change in the invoice number? Please describe these two types.
Why do you need a valid invoice for every ID?
I'm not trying to argue here, I'm trying to understand the problem.
Same here with the arguing ( I'm grateful for the help you provide ).
So, I have too types of invoices which are done ( Proforma, Fiscala ). All invoices start as "oferta" which is offer and can become one of those 2 types. After they become x or y I print the invoice (therefore good invoice nr is required), but if the invoice is canceled (by the client lets say ) then I have to delete it.
This is why right know I have a global field for Proforma and one for fiscal which take value of (Select max (invoice id/ type) + 1 ).
The same with the invoice number, but here if they are done at the same time for the same type then I'll get two invoices with the same invoice nr. (Problem)
I do the incrementing by (Select max (invoice id/ type) + 1 ). Is there a way to pause the script until this is done so I don't get same max()+1 for 2 invoices. Or do you have any other idea.
Thank you :)