Enforce relationship match in FileMaker - filemaker

I have two FileMaker tables that are linked using a relationship. The relationships matches based on the content of two fields:
TableA.Foo matches TableB.Foo
TableA.Bar matches TableB.Bar
Is there a way to enforce constraints on this relationship in FileMaker? When entering objects in TableA, I'd like to ensure that the values entered in fields Foo and Bar are such that there exists a corresponding record in TableB. Is this possible?
Bonus points if I could somehow autocomplete values of Bar based on the entries of TableB and the value already entered in Foo.

To answer your question as asked:
You can validate the Bar field (or any other field) by
calculation:
not IsEmpty ( TableB::Foo )
Set the validation to validate Always. This will throw a
validation error if you try to commit a record in TableA without
having a related record in TableB.
To auto-complete based on values in another field, you must format
the target field as Drop-down list with Auto-complete using a value
list.
Before defining the value list, set up a new relationship (using a
new occurrence of TableB) as:
TableA::Foo = TableB 2::Foo
Then define the value list to use values from TableB 2::Bar, show only related values starting from TableA.
I suspect there may be better ways to accomplish whatever you're trying to accomplish here.

Related

Sqlalchemy way to handle select based on outdated data

Assuming I have a table sets with a field filters, containing array of key - value mappings, table items to which select query must be applied to extract rows based on these filters, and associated table for M:M relations to link each set with each item. I am seeking for a method or mechanism to cancel select query if sets.filters were updated, otherwise M:M relation will be built invalid as based on yet not refreshed filters.
The concrete scenario when a problem takes place is:
Receive file with items data, to parse, and insert into items returning new relevant ids(primary keys here);
After insertion, select from relevant sets for filters;
Take items ids and select from items using filters;
Update M:M association table for all the items returned at step 3.
So, unfortunately between step 3 and 4 or even earlier, API call makes an update on one of the sets rows, changing its filters. As the result - M:M table is invalid, because one filter was changed(lets say the filters contained kind of weight <= 100 kilos expression, however after the mentioned update it has become weight <= 50 kilos, so if there are some new items with weight greater than 50, those items ids should not be in M:M table, obviously).
Is there some efficient way to cancel select query from items during transaction? Or maybe there is a strong query to use. My idea is to rollback changes post-factum, checking sets.modified_at column. But it seems as doing additional job by wasting disk and cpu time.

ms access form listbox changing whole field

I have created a form to update a query that that is in turn based on a master table containing information on a number of files. This master table is then related to several other tables in say for example a table called group_table, defining which group the file would belong to, which contains an ID field and the group_name. This is then related in a one-to-many relationship with the master table based on the group.ID and a field in the master table master_table.group and joined in the query the form is based on.
In the form I have designated a listbox control to update the group field of the query/master table. The contents available for selection in the list box were set based on the group_name field from the group_table table which is defined in the RowSouce section of the property sheet of the form.
So my issue is that when I try and update any records in the query using the listbox in the form, all of the records that are the same will get changed as well. E.g., changing a record in one row from "Group A" to "Group B" will change all the records containing "Group A" to "Group B" in the group field. So I was wondering if there is anything I can do to set it so only the specific record that I want to change gets changed.
When you are making the call to update the table you should make sure that you are using WHERE along with the primary key to make sure that you update that row only. An example would be a statement similar to the one below.
CurrentDb.Execute "UPDATE [group_table] AS G INNER JOIN [master_table] AS M
ON G.[ID] = M.[groupID]
SET G.[group] = '"& Group A & "'
WHERE M.[groupID] = '" & groupIDFromForm & "';"
Apply the ON from the join so that the foreign key and primary key are going to share the same value, and from there use the form to create a variable that you can use to identify the exact row. From there the program should execute the query correctly.

Filemaker auto enter calculation - update with relationship

According to the Filemaker documentation,
If you select Calculated value, you can edit the field value in Browse mode (if Prohibit modification of value isn't selected). The value is calculated when you create a record, or when one of the referenced fields changes and the destination field is empty. (However, if you select Do not evaluate if all referenced fields are empty in the Specify Calculation dialog box, the value isn't calculated when you create a record and all fields referenced by the calculation are empty. Instead, the value is calculated when one of the referenced fields contains a value.
An auto enter calculation will be calculated if the reference field value used in the calculation is changed. I'm using a field in the relationship and from that same relationship I'm getting the value from a related table.
For example, relationship between table A to B is based on a field F1. In my calculation, I've
B::__text
Here, in this calculation I'm not using the field F1 but it used in the relationship between A->B. Whenever I'm changing the value of F1, Filemaker is updating the value of the auto enter calculation.
Is this normal? I don't find any docs related to this in the documentation.
Yes, it is expected behavior as long as the "Do not replace existing value of field" is not selected.

FileMaker - Getting Data From Another Table with Multiple Field Restrictions

I can't think of a better title, so feel free to make a suggestion once you understand the issue.
I was given a table to work with that I need to call from another table:
Name
Month
Type
Value
For each record in the main table I need to pull one "Value" that corresponds to it. What it is will be determined by all three of the other fields. So for example, if a record in the main table is:
Name:
Google
Date:
3\17\2016
Type:
M
Then I need to pull the value for the record in the other table where the Name is "Google", the month is "3", and the type is "M".
I was able to do this successfully (if slowly) using an ExecuteSQL command in a calculation field, with a ton of nested If statements for the names (I have yet to figure out how to input the record's data directly into the ExecuteSQL statement, it breaks when I try). I would prefer to just grab the data directly. I can't switch over to the other layout because I need to see all of the records at once. I can't do a simple relationship because there isn't a real relationship, it's like there are three foreign keys working in tandem and I only know how to use one to call the data.
Any idea on how to do this more simplistically?
Some ideas I've had but not sure if it will work:
Using a calculation field as a related field to dynamically point to the row by code (concatenate the three relevant fields into a type of code). Not sure if you can connect two tables by a calculation field.
Doing that same thing when calling the data into the table in the first place, adding a code to create a single primary key.
Here are my relationships:
I can't do a simple relationship because there isn't a real
relationship, it's like there are three foreign keys working in tandem
and I only know how to use one to call the data.
Simply define a relationship with three predicates - i.e. three pairs of match fields.

Create a new FileMaker layout showing unique records based on one field and a count for each

I have a table like this:
Application,Program,UsedObject
It can have data like this:
A,P1,ZZ
A,P1,BB
A,P2,CC
B,F1,KK
I'd like to create a layout to show:
Application,# of Programs
A,2
B,1
The point is to count the distinct programs.
For the life of me I can't make this work in FileMaker. I've created a summary field to count programs resetting after each group, but because it doesn't eliminate the duplicate programs I get:
A,3
B,1
Any help much appreciated.
Create a a summary field as:
cntApplicaiton = Count of Application
Do this by going into define fields, create a field called cntApplication, type summary. In the options dialogue make the summary field a count on application
Now create a new layout with a subsummary part and nobody. The subsummary should be sorted on Application. Put the Application and cntApplication fields in subsummary. If you enter browse mode and sort by Application you ought to get the data you want.
You can also create a calc field with the formula
GetSummary(cntApplication; Application)
This will allow you to use the total number of Applications with in a record
Since I also generate the data in this form, the solution I've adopted is to fill two tables in FileMaker. One provides the summary view, the other the detailed view.
I think that your problem is down to dupliate records and an inadequate key.
Create a text field called "App_Prog". In the options box set it to an auto-enter calc, unchecking the 'Do not replace...' option, and use the following calc:
Application & "_" & Program
Now create a self join to the table using App_Prog as the field on both sides, and call this 'MatchingApps'.
Now, create (if you don't alread have one) a unique serial number field, 'Counter' say, and make sure that you enter a value in each record. (Find all, click in the field, and use serial number option in'Replace Field Contents...')
Now add a new calc field - Is_Duplicate with the following calc...
If (Counter = MatchingApps::Counter; "Master Record" ; "Duplicate")
Finally, find all, click in the 'Application field, and use 'Replace Field Contents...' with a calculation to force the auto-enter calc for 'App_Prog' to come up with a value.
Where does this get you? You should now have a set of records that are marker either "Master Record" or "Duplicate". Do a find on "Master Record", and then you can perform your summary (by Application) to do a count of distinct application-program pairs.
If you have access to custom functions (you need FileMaker Pro Advanced), I'd do it like this:
Add the RemoveDuplicates function as found here (this is a recursive function that takes a list of strings and returns a list of unique values).
In the relationships graph, add another occurrence of your table and add an Application = Application relationship.
Create a calculated field in the table with the calculation looking something like this:
ValueCount(RemoveDuplicates(List(TABLE2::Program)))
You'll find that each record will contain the number of distinct programs for the given application. Showing a summary for each application should be relatively trivial from here.
I think the best way to do this is to create a separate applications table. So as you've given the data, it would have two records, one for A and one for B.
So, with the addition of an Applications table and your existing table, which I'll call Objects, create a relationship from Applications to Objects (with a table occurrence called ObjectsParent) based on the ApplicationName as the match field. Create a self join relationship between Objects and itself with both Application and Program as the match fields. I'll call one of the "table occurrences" ObjectsParent and the other ObjectsChildren. Make sure that there's a primary key field in Objects that is set to auto-enter a serial number or some other method to ensure uniqueness. I'll call this ID.
So your relationship graph has three table occurrences:
Applications::Applicaiton = ObjectsParent::Application
ObjectsParent::Application = ObjectsChildren::Application, ObjectsParent::Program = ObjectsChildren::Program
Now create a calculation field in Objects, and calculating from the context of ObjectsParent, give it the following formula:
AppCount = Count( ObjectsChildren::ID )
Create a calculation field in Applications and calculating from the context of the table occurrence you used to relate it to ObjectsParent with the following formula:
AppCount = ObjectsParent::AppCount
The count field in Objects will have the same value for every object with the same application, so it doesn't matter which one you get this data from.
If you now view the data in Applications in list view, you can place the Applications::Application and Applications::AppCount fields on the layout and you should get what you've requested.