dbTalk Databases Forums  

Re: How to block related records while running a script

comp.databases.filemaker comp.databases.filemaker


Discuss Re: How to block related records while running a script in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
B Collins
 
Posts: n/a

Default Re: How to block related records while running a script - 07-30-2003 , 07:30 AM








"Jon Gutiérrez" wrote:
Quote:
Hi,

Hi group,

I sent this message a few days ago, but got no replies. Maybe I am not
clear in my explanations. Please let me know. In any case: can you
help me with this?

TIA

I am running a Server/Client solution (FM 5.0 Server /FMPro 5.5 v3 /
Win 2000 / TCPIP)

DB1 - master, step1
DB2 - portal, related records
DB3 - master, step2

The user, being in RECORD1-1 in DB1, in a layout that shows a portal
(PORTAL1-1) with related records from DB2, chooses a button that
runs SCRIPT1. The script creates a new record (RECORD3-1) in DB3
using info from the current record (RECORD1-1). Then goes through a
loop that moves from the first to the last record in the portal
(related records from DB2) "assigning" this records to RECORD3-1 in
DB3- The final result is the new record in DB3 that shows a portal
containing exactly the same related records that RECORD1-1 showed in
PORTAL1-1.

I use this procedure to invoice a project. This way, I create a new
invoice that takes some info from fields in DB1 and copies the related
records (the products to be invoiced) to the new invoice.

The problem I have is that, being in a network environment with many
users, it happens from time to time that one or more records in
PORTAL1-1 are lock by some users at the moment of invoicing. If this
happens, the program start creating endlessly new lines in the related
portal.

I need a way to control if related records in PORTAL1-1 are being
used, and, if they are being used, either skip the invoicing at all,
or maybe wait until the record becomes available (this might probe a
problem after all if the user does not release the record promptly).
Maybe advising the user to unlock the record is a solution?

Any ideas?

Thanks

Jon

I guess I don't understand why you are using a script. Why not set up
the relationships and portals in such a way that you can create a new
record as desired directly in the portal? I don't understand what you
are trying to do clearly enough to give you step-by-step intructions,
but it should be easy to do it this way. Then you won't have any looping
scripts that get you into trouble, and the creation of new records will
be quick and easy.

To take a stab at your situation, with the information you gave, it
sounds like DB1 contains the info needed to create the invoice. It
sounds like DB3 contains the invoices. It's not clear to me what DB2 is for.

If all the info needed for invoicing is in DB1, and the invoices are in
DB3, a simple approach would seem to be to define a relationship between
DB1 as master and DB3 as related. You would need to have a unique
identifier field for each of the DB1 records, and an identifier field of
the same type in the DB3 records, with the relationship defined using
this key identifier field. This allows a one-to-many relationship, with
each record in DB1 having many related records in DB3. Define the
relationship to allow creation of related records. Set up a portal from
DB3 in a layout of DB1. Put appropriate fields from DB3 in the portal.
Then, when you click on the first empty row of the portal and enter
data, a new related record is automatiaclly created in DB3.

If DB2 contins information that you need for invoicing, or if the
situation is more complex, let us know and we will try to help.

Bill


Reply With Quote
  #2  
Old   
Jon Gutiérrez
 
Posts: n/a

Default Re: How to block related records while running a script - 08-01-2003 , 06:19 AM






Dear Bill,

Thank you for your reply.

Quote:
I guess I don't understand why you are using a script. Why not set up
the relationships and portals in such a way that you can create a new
record as desired directly in the portal?
... it sounds like DB1 contains the info needed to create the invoice. It
sounds like DB3 contains the invoices. It's not clear to me what DB2 is for.
DB2 keeps the related records for both DB1 and DB3. It is a
one-to-many relationship (one record in DB1, several related records
in DB2, and the same thing for DB3). Think about it this way: DB1 hold
the statement info (client name, order number, etc.). DB2 holds the
item requested (it contains the keys to DB1 and DB3 and info like item
price, item quantities, etc.). DB3 is the invoice. It contains more or
less the same info as the related record in DB1, but also contains
some info not present in DB1, and has its own counter.

Quote:
If all the info needed for invoicing is in DB1, and the invoices are in
DB3, a simple approach would seem to be to define a relationship between
DB1 as master and DB3 as related.... This allows a one-to-many relationship, with
each record in DB1 having many related records in DB3
Not really.

DB1 to DB2 = one to many
DB3 to DB2 = one to many
DB1 to DB3 = one to one

The script is run from a button in DB1. It creates a new record in
DB3, copies the key from related record in DB1, copies all the
necessary info from DB1 to DB3. THEN, and this is the problem, loops
from record 1 in DB2 to record n in DB2, assigning to them the key
from the newly created record in DB3. The issue here is that in a
network environment, it is likely that somebody could be modifying one
of the records in DB2 that the script has to lock to add the key from
the new record in DB3. In fact, it happens many times that somebody in
modifying one of the needed records in DB2 (for instance, somebody
could be updating the item price, adding the stock number, etc.). If
this happens, the loop does not know what to do and for some reason
ends up creating several hundred blank records in DB2, until the user
(or myself) stops the script.

I need a way to "tell" the scrpipt: "Hey, if you find a locked record,
send the user a message to get out from that record" or maybe "Hey,
before you run the script, check whether somebody is using any of the
related records in DB2, and if it is so, either send them a message or
void the whole script and tell the user to run the script later on.

First thing:

- I do not know what error number in FileMaker tells me that somebody
is using the record that the script is trying to modify

Second:

- Even if I knew this error, the only thing I could do is to stop the
script at that point (that would be a terrible solution!) or send a
message to the user (not a good solution either!). The best solution,
to my knowledge, would be to check availability of related records,
lock them before doing anything else, and then runnig the script. That
would take care of the locking problem and make sure that the script
is run from beggining to end without problems.

Any ideas anybody there?

Thanks

Quote:
Bill


Reply With Quote
  #3  
Old   
Jon Gutiérrez
 
Posts: n/a

Default Re: How to block related records while running a script - 08-01-2003 , 06:29 AM



Hi Bridget,

Thank you very much for the info you provide in your reply. I have
checked the articles and they seems very interesting. I am going to
try and see if I can apply some of the ideas to solve my problem.

I am not really keen on stoping a loop until the record becomes
available, because sometimes this could be several minutes more than
the user is willing to wait. Besides, if this happens several times a
day, then it is likely to generate frustration in the user. I am more
into checking record availability and locking records prior to running
the script, and if they cannot be ALL locked at once, then avoid the
whole process and tell the user to run it later on. This might sound
drastical, but it might be better to keep the database integrity after
all.

Jon



On Thu, 31 Jul 2003 10:11:37 +1000, Bridget Eley
<bridgeteley (AT) ihug (DOT) com.au> wrote:

Quote:
in article b16fiv88unknttu81rm9pqh61sp32u0j6s (AT) 4ax (DOT) com, Jon Gutiérrez at
jguti (AT) qqqhotmail (DOT) com wrote on 30/7/03 8:05 PM:

I need a way to control if related records in PORTAL1-1 are being
used, and, if they are being used, either skip the invoicing at all,
or maybe wait until the record becomes available (this might probe a
problem after all if the user does not release the record promptly).
Maybe advising the user to unlock the record is a solution?

Do a search on "record locking" within comp.databases.filemaker at

http://www.google.com/advanced_group_search?hl=en

Lynn Allen in particular has posted some useful and informative articles on
this topic. Or perhaps Lynn herself could dazzle us all (for the nth time)
with even more cutting edge techniques for overcoming this problem?!

Bridget Eley




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.