fbugeja Posted November 12, 2012 Posted November 12, 2012 Hello all I am in the process of creating a contacts database with 2 layouts (CONTACTS and DONATIONS). On the CONTACTS layout is a portal which shows the data from 4 fields - Donation Date, Donation Amount, Receipt Number, Donation Use - from another layout (called DONATIONS) in the same database. My request What I am looking for is a button called "Add Donation" to be placed on the CONTACTS layout next to the portal which, when clicked, takes the user to the DONATIONS layout and creates a new (donation entry) record. Here the user enters details to 4 fields - Donation Date, Donation Amount, Receipt Number, Donation Use - that are included in the portal on the CONTACTS layout. After they enter these details, they click a button called "Update" which takes them back to the CONTACTS layout and updates the portal with the new donation. I am aware of the need to create a relationship between the 2 layouts and both layouts will be linked through a common field called CODE (numeric, indexed, serial number). While I know it would be easier to create a setup on the CONTACTS layout whereby users can enter the Donation Date, Donation Amount, Receipt Number, Donation Use directly into the portal, I do not want this to happen. I want to make the database user-friendly to non-teckies. Can anyone help me with scripts for the Add Donation and Update buttons? Also, is there anything I need to select when you go to File > Define > Database > Relationships? Frank
Ron Cates Posted November 12, 2012 Posted November 12, 2012 Hi Frank I am aware of the need to create a relationship between the 2 layouts and both layouts will be linked through a common field called CODE (numeric, indexed, serial number). Let's start here. It is important that you understand terminology and structure when using Filemaker and when asking questions on the Forum. So to begin with, relationships are between Tables or Table Occurrences not between layouts. Relationships are established using key fields. The parent table will have an auto enter serial number field usually called "ID" or "_pk_id" or something similar to indicate it is the primary key. A child table will have a foreign key field to hold the value of the Primary key of it's parent. It will be either a text or number field with no auto enter serial. The field name should indicate what id it holds. For example, "_fk_contact_id". This field recieves the ID of the parent record to establish the relationship. So If John Smith is a contact with a serial id of 10, all donations made by John Smith will have a 10 in the Donations foreign key field to indicate that they were made by John Smith. Now, to create a new Donation for a contact using another layout you will need a script that first captures the primary key of the contact record you are adding the donation to, carry it to a new layout based on the Donations table, create a new Donation record and set the foriegn key field with the Contact id. Something like this Set Variable [ $id; Value;Contacts::_pk_id ] Go to Layout [ "New Donation" (Donations) ] New Record/Request Set Field [ Donations::_fk_contact_id; $id ] I see your profile shows you on FileMaker 7. If that's the case I'm not sure if you have variables, in which case you would need to use a global field to store the ID to carry to the new record layout. 1
comment Posted November 12, 2012 Posted November 12, 2012 Variables did not occur until FM8. So use the script parameter instead.
fbugeja Posted November 13, 2012 Author Posted November 13, 2012 Hello Ron Firstly thank you for your reply. You are right in saying that relationships are formed between tables and not between layouts. In my attempt to keep my query short, I neglected to state that the database contained 2 tables, also called CONACTS and DONATIONS that are linked via a key field called CODES. It was incorrect for me to say that there was a relationship between two layouts. I am using FMP 8 QUERY: should the update button have the following script? Go to layout [CONTACTS] Go to Related Records [from .. Using layout ..] You made use of variables in your script for the Add Donation button. I am not familiar with the use of variables in scripts. Am I right in assuming that reference has to be made to the variable used in the Add Donation button script? Cheers! Frank
David Anders Posted November 15, 2012 Posted November 15, 2012 You may find the free open template from Richard Carlson worth looking at. http://www.filemakerdonations.com/
Ron Cates Posted November 16, 2012 Posted November 16, 2012 Hi Frank. You wouldn't use Go To Related Records when creating a new related record because the related record does not yet exist to go to. You need to create the relationship when you create the new record by putting the Primary Key ID of the Contact into the Foriegn key field of the new Donations record. Using variables can be thought of in a way like using copy and past. The same thing can be accomplished by copying the Primary Contact ID, going to the donations layout, creating a new record and pasting the ID into the Foriegn Key field. However, using Copy and Paste is not considered good practice for various reasons. Setting a variable is much the same however. You set a variable such as $id to hold the Primary Key of the contact so you can cary it to the Donations layout and use Set Field to put it in the Foriegn Key Field of the new record. Thus relating the new Donation to the Contact.
Recommended Posts
This topic is 4726 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 accountSign in
Already have an account? Sign in here.
Sign In Now