Can you break down your question into "when i do this...then A happens and i want B to happen? What you wrote is difficult to comprehend. Clarity is significant in getting effective answers here.
A > User go to layout to create OPD "Means New Record"
B> When they hit button new OPD above script works and New record is created
C> Things go fine until two users press the new OPD button at once
D> When two users press new OPD button at once, both are allocated the same OPD Number.
E> Both users enters the Data and when they press print OPD
F> One Users get print out and when other users enters the data and press print out,
G> He gets the printout of the other user who has already made that record.
Your OPD table needs to have an auto enter auto increment serial number or auto enter calculation of Get (UUID) for the primary key.
The user never needs to see the PK field so it does not have to be smart like your calculation.
The two consecutive set fields (one that sets the PK for the record) can cause collision on simultaneous triggering of the script, or near simultaneous, by two distinct users. It takes a brief bit of time to process execute sql select statements that increases the chance of collision. Use auto enter fields validated as not empty and unique for PK values eliminates this chance occurrence.
You should also look at setting a variable to the contents of current date because calling get ( CurrentDate ) 7 times is wasteful of CPU cycles and causes more delay
i actually found where the problem is
ExecuteSQL ( "SELECT Max(IDsub) FROM OPD WHERE OPD_Month=? AND OPD_Year= ?";"";"";MonthName ( OPD::CDate );Year ( OPD::CDate ) )+1 <<< this one is causing the duplication can you help me out in adding this 1 as FIFO or time based , cause when both buttons are press at once from both users. number are given to both are same
Auto increment serial number fields or UUID fields as primary keys solves this issue.
If you insist on using your calculation to set the primary key value then you will always have the possibility of data collision for multiple users unless validation is enabled OR if you switch to a more transactional approach to your scripting.
Goolge FileMaker Transactions and get familiar with the work done by Todd Geist and the rest of the community.
Set field definition OPD::OPD_idPK to be validated always as unique and not empty.
Do not allow user to override.
Enable validation on the commit records script step.
Program around the situation when validation fails for the duplicate entry.