Create record in related table *only* if not previously existing there - filemaker

I have a Filemaker database with a Members table, an Events table, and a join table called Attendance which should list which members attended which events. Attendance has the setting "allow creation of new records" ticked for Members (doesn't need it for Events).
Data arrives in an Excel spreadsheet for importing to Attendance. But then I want to see if there are people attending who aren't in our records already... sort of like this:
look at each of the newly added records in the attendance table
see if the members mentioned there exist in the member table
if so, do nothing
else create a new record in the member table for them, using data from the attendance table.
If I'm understanding it correctly, Steps 3 and 4 should look something like this:
Set Variable [ $fname; Value: Attendance::firstname ]
Go To Layout ["Member" (Firstname)]
New Record/Request
Set Field [Member::Firstname; $fname]
i.e. put the desired info into variables, start a new record in the related table and set the data there to the value of the variables.
But how do I get step 2 happening? I'm guessing some sort of loop will go through the found set of records in Attendance, and grab the relevant identifier. How do I show that to the Member table to see if it's present or not?

"Firstname" might be a bit light to pinpoint a unique member, if you have many members !
I'd presume therefore you would have some sort of unique key for each member.
As from there, just search for the member in the member base, before creating the new record…

Link the two tables with an EQUALS relationship.
Write a script:
// Loop through your attendance records.
// Be sure you're in the correct layout
Go to Layout ["imported list"]
// Attempt to go to the membership record of the person who is attending the event.
Go to Related Record [Show only records from: from table: "membership table"; using layout: "membership table"
// If the person who is attending IS in the membership list, you'll go to that member's record in the "membership table."
// If the person who is attending is NOT in the membership list, you'll get an error. You can use that error in an if statement to execute code to add that member.
If [Get ( LastError ) = "101"]
// insert code to add new member
End if

Since you already have a relationship between Member and Attendance, it means that you can "see" any related Members from the Attendance table across the relationship.
We also know that you only need to evaluate the new attendance records coming in from your spreadsheet.
I also assume that there could possibly be be more than one attendance record per Member in the spreadsheet. This may not be the case, but it's safer to assume it's possible.
I'm also assuming that you are linking the Member table to the Attendance table via the primary key in Members and a foreign key in Attendance, i.e. Member::ID = Attendance::Member ID.
So here's the script process I suggest:
Import the new Attendance record into the Attendance table.
This will give you a found set of only new attendance records
From the Attendance layout, perform a find for related Member records with an omit, i.e.:
# This assumes you're already on the Attendance layout
Enter Find Mode
Set field [Member::ID ; "*"]
Omit record
Constrain Find
This will give you a found set of new Attendance records that do not have matching Member records.
From here you could loop through each of the attendance records and create the Member records as needed.
If you check the Allow creation on the Member side of the Member -< Attendance relationship, you could set the field in the Member table directly from the Attendance layout.
Since the 1 to Many relationship between Member and Attendance goes 1=Member Many=Attendance, you would need to check to be sure you haven't already created a Member record during your loop, i.e. If a new Member had multiple Attendance records you could have already created a Member record during the loop.
Your loop would look like this:
Go to Record [First]
Loop
If [IsEmpty(Member::ID)]
Set Field [Member::First Name] // This first Set Field will create your new Member Record as long as the "Allow Creation" is enabled on the Member side
Set Field [Member::Last Name]
... This would be the rest of your set field steps for Member
End If
Go to Record [Next ; Exit After Last]
End Loop
This way you don't need to navigate away from your Attendance record set. Also, the Primary and Foreign keys for both tables will be created and set automatically through the attributes of the relationship itself.

Related

How to map in JPA a field that can hold a foreign key to on of two tables?

I have the following DB tables: Teacher and Student. They contain a few common fields I would like to hold in my java code in a Person class, which will be the parent class of my Teacher and Student entities. I also have an Event table, that contains an organizer field. The organizer field contains the id of either a Teacher or a Student.
The question is, can this be mapped in a way that the event contains a Person type as organizer? If not, what other options do I have?
Of course, there are plenty of solutions that require me to query the organizer separately from the event, I would like to avoid that.

Trigger to Count records in self relationship salesforce

I am working on one scenario.
I have an object called "Property_Assignment__c" which has two record types.
1) Primary Property Assignment
2) Secondary Property Assignment
Its also having a self lookup relationship and this lookup field "Primary_Assignemnt__c" is available on "Secondary Property Assignment" page layout which is lookup to "Primary Property Assignment".
Now if I create any records in "Secondary Property Assignment" record type then I need to count and save in "Number_Of__Dependents" field in "Primary Property Assignment".
Can anyone help me to solve this problem if possible please.
If you want to count the Secondary Property Assignment records you should go with trigger only. we can use Rollup summary to count the no of Secondary Property Assignment records when the master-detail relationship is available.
But here u have self-relationship. So you can write a trigger to count the no of records.

MS Access Filter Child Table by Record Chose on Form

I'm trying to create a simple 2 table database - table 1 holds ClientInfo and table 2 has ClientVisits - Relationship is on ClientInfo.ID->ClientVisits.ClientID. Then I have a form created thus for viewing the ClientInfo plus a child(sub?)table which SHOULD show all the records from ClientVisits where my Form ClientID = ClientVisits.ClientID.
Here is my form
Here is the child table with fields shown
Relationships
So I already have one record in ClientVisits for the currently chosen ClientID form record. But it doesn't show in my Table.ClientVisits. Other than the relationship I don't have any other link between the ClientID and the ClientVisits.ClientID field.
If I need to post further info please let me know, trying to describe this as well as I can - sorry if it's not making sense. Thanks.
You have to link both tables in your form.
In my example, main data of my form is a table called CLIENTES, where it shows all the information about a cliente. It would be exactly the same as your table ClientDetails. In this table, primary key is a field called DNI (it would be the equivalent of your ID field)
I got a second table called CONSULTAS MÉDICAS. This table is just a list of how many times this client comes to see us. It would be the same as your secondary table CLIENT VISITS. In this table, I got a field called PACIENTE, linked to my table CLIENTES. Let me show you.
Ok, now my form is done based on the data of my table CLIENTES, but I got a subform control, where I have linked the table CONSULTAS MÉDICAS
To make this work is pretty easy. Not filters or queries. Just linked child and master fields. To do this, you have to select properties of your subform control, and then go to DATA TAB
Just choose as main field your ID field from table CLIENT DETAILS and link it to child field CLIENT ID from table CLIENT VISITS
That should work for you.

How to correctly add a list of objects to database, working with multiple tables?

My database looks like this: Database Diagram MSSMS
So everytime i'm adding a fish to the database, i want to add the fishes's continent, waterlagen and verbanden.
Tables Continenten, Waterlagen & Verbanden are already filled with objects from an array after creating the database.
Im using List Continenten; for example to store multiple continents.
So i tryed:
Vis nieuweVis = new Fish();
nieuweVis.Naam = "Molly";
foreach(Continent c in Continenten)
nieuweVis.Continenten.Add(c)
so in the table VisContinenten
i assume that EF will automaticly fill in the FishId and ContinentId wich are foreignkeys.
I want records in that table also to be unique so i add a unique key to both the columns in VisContinenten so that fish 1 on continent 1 won't appear twice in that table.
Error i get:
An error occurred while saving entities that do not expose foreign key
properties for their relationships
Additional information: Unable to update the EntitySet 'VisContinenten' because it has a DefiningQuery and no element exists in the element to support the current operation.
Help me pls :)
Thank you

Make a record in one Entity Inactive when a value is changed in another Entity of the same record in crm 2011 on-premise

I have two entities, Bookings and Discharge.
When a record is created in Bookings, it automatically creates a record in Discharge. Discharge
has an additional field that is a drop down with four options.
I want a functionality where when any one of the values in drop down is chosen, the similar record in Bookings
should shift from "Active" view to a default view which I have created by the name of "Processed" in Bookings.
What I have in mind is to create a hidden field in Bookings that is populated when I choose one of the options from Discharge drop down and based on that field the record should shift the view in Bookings. But how do I populate the hidden field? Workflow is not giving me that option or maybe I am doing something wrong.
Help?
So I have created a 1:N relationship between Booking and Discharge. The field is updated in Booking based on the field in Discharge and I choose the particular record in Booking from the look up field in Discharge. But I want to get rid of this second step. I don't want to choose the record in Booking entity but directly update it from Discharge. There are some fields and their values common in both forms, can I create a relationship based on that?
Regarding the first part of your question
"What I have in mind is to create a hidden field in Bookings that is populated when I choose one of the options from Discharge drop down and based on that field the record should shift the view in Bookings. But how do I populate the hidden field?"
If the field is not on a form you can't set its value hence the following:
I don't believe you can set a hidden field using a workflow. However there is a 'visibility' option on the form designer.
I suggest you add your "hidden" field to the form. Then double click on it and toggle the "Visible by default" checkbox. This will hide the field from the user.
You can then set the value of this field using a workflow.
Regarding part two of your question
I don't want to choose the record in Booking entity but directly update it from Discharge. There are some fields and their values common in both forms, can I create a relationship based on that
You have a 1:N relationship however you want to set the related Booking Dynamically is this correct? You cannot select a Booking in the lookup field based on criteria from a workflow. You would need to use a plugin.
If the Discharge has a related Booking (the Booking lookup on Discharge is already set) then you can use a workflow to either:
1) Set a field value (Using 'Update Record' in the Workflow steps) in the parent Booking
2) set to Inactive (Using 'Change Status' in the Workflow steps) in the parent Booking