FileMaker Pro - Sum of the specific record in the portal - filemaker

I have a Portal that shows related records from GJ (General Journal). It has two fields inside the portal.
First field is DebitTitle, the records that are being save in this field are "Cash in Bank" and "Inventory".
Second field is Debit, the records that are being save in this field is the amount in every DebitTitle.
So, my problem is, how can i get the sum of all the "Cash in Bank" record only?
I tried to create a calculation type field:
If ( GJ::gj_DebitTitle = "Cash in Bank" ; Sum ( GJ::gj_Debit ) )
But it didnt work. The calculation field is getting the sum of the Debit field records.
I also tried to create a script trigger in my portal:
If [ GJ::gj_DebitTitle = “Cash in Bank” ]
Set field [ USR::gj_SampleSum ; Sum (GJ::gj_Debit) ]
Commit Records/Request [ Skip data entry validation ; No dialog ]
End If
It didnt work also, it just filter my portal and display all the "Cash in Bank" records.

Your key fields look strange. Seems there are primary and foreign key fields that you don't use. usr_ID and gj_UsrID. Remember that the Sum function works across a group of related records or a record with repeating fields and not across a found set of records. If I understand your need correctly, the sum functions belong in the parent table, not in the portal with related records.
Set up 2 calculated fields in GJ that are very similar to what you have:
DebitIfCashInBank:
If ( GJ::gj_DebitTitle = "Cash in Bank" ; GJ::gj_Debit )
Do a sum on those in the USR table:
SumDebitIfCashInBank:
Sum(GJ::DebitIfCashInBank)
Hope this helps.

Related

use executeSQL() to populate portal in Filemaker

I have a client with a Filemaker 16 app that uses an ODBC connection to a SQL Server DB. With Filemaker, everything I know about databases seems to be wrong. I have wrestled for 2 days with this and only ask as a last resort --- is it possible to populate a portal field with the results of a SQL query? I am trying to return unique records and exclude duplicates. Where would the executeSQL() call go? I thought perhaps in the Filter on the Portal, but that is not it. Sorry for the basic question.
A FileMaker portal will always show the records matching a given relationship in the Relationship graph. This set of records can be further constrained by the portal filter.
To achieve a list of unique items, you will need to create a calculation field in your related table that determines if the record is unique. This can be done in many ways, ExecuteSQL being one. You can then use this field as a predicate in the relationship itself or use it in the portal filter.
This is just one way to do it.
In the (shadow) table you want to display record from, create a calculation field that returned 1 if the record should be included and 0 if it should be omitted. It might be something like this:
Let (
[
_sql = List (
"SELECT id" ;
"FROM table" ;
"WHERE match_field = ?" ;
"ORDER BY id" ;
"FETCH FIRST 1 ROW ONLY"
) ;
_id = ExecuteSQL ( _sql ; "" ; "" ; match_field )
] ;
_id = id
)
Now in the table you want to show a portal from, create a global calculation field, ONE that returns 1 and then create a relationship between that table and the one you want to view a portal of using ONE and the SQL calc above as the match fields.
On a layout with a context into the LAYOUT_CONTEXT table above, you can create a portal into SHADOW_TABLE.

Filemaker: Copying records from one table to another

I have a database with tables ( case, knowledgebase)
Case table has fields linked to a specific customer
Knowledgebase table is separate and doesn't care about customer.
I want to have the user click a button occasionally to copy their solution (from Case Table) to a new record in knowledgebase table (just two fields, desc, solution)
I just don't know the steps to 'copy'
Roughly:
Set Variable [$desc; Value: Case::desc]
Set Variable [$solution; Value: Case::solution]
Go to Layout [ Knowledgebase ]
New Record/Request
Set Field [Knowledgebase::desc; $desc]
Set Field [Knowledgebase::solution; $solution]
Commit Records []

How do I make filemaker recognize records from an imported file

I imported an excel list of student names and ID's. The teachers job is to either scan or manually enter student ID's and when done so, filemaker will automatically add the student name from the excel list. If the teacher mistyped the student ID, then the name would not show because it is not in the excel list. How do I make filemaker tell the user to stop and retype the student ID not allowing the teacher/user to add anymore students until they fix the current mistyped ID?
How do I make filemaker tell the user to stop and retype the student
ID not allowing the teacher/user to add anymore students until they
fix the current mistyped ID?
You can (and should) validate the field. The validation here could be as Member of value list: [StudentIDs], where "StudentIDs" would be a value list using values from the StudentID field in the imported table.
Note: Filemaker's validation error messages can be somewhat intimidating to the users, so you may consider adding a script triggered OnObjectValidate to run a "pre-validation" check and guide the user in case of an invalid entry, for example:
If [ IsEmpty ( FilterValues ( Attendance::StudentID ; ValueListItems ( Get (FileName) ; "StudentIDs" ) ) ) ]
Show Custom Dialog [ Message: "There is no student with this ID. Please correct your entry."; Buttons: “OK” ]
Exit Script [ Result: 0 ]
End If

Filemaker - Summing a field based on another field

In Filemaker Pro 12, I am trying to write a formula for a calculation field that will sum a field in a related table based on another field in that same related table. The normal Filemaker sum equation would look like this:
Sum (Assets::Asset Quantity)
However, I need to specify that only quantities that are related to a field named Asset Type with a value of "Building" will be used to filter the values in Asset Quantity that will be used in the sum.
There are a couple of ways that you could do this:
A new Calculated field
First, you could add a new Calculation field to your Assets table called, say, Building Quantity, with a Calculated Value of:
If (Asset Type = "Building" ; Asset Quantity ; 0)
And then you can use the sum of this new Building Quantity just like you were using Sum(Assets::Asset Quantity) before.
A new relationship
Second, you could add a new Calculated field to your main table with the value always equal to "Building" and then add a new table occurrence of the Assets table. We'll call it "BuildingAssets" and set the relationship so that your IDs match and also your new "Building" field matches the Asset Type
Summary ID \____________/ BuildingAssets::Summary ID
BuildingText / \ BuildingAssets::Asset Type
Then you will use
Sum (BuildingAssets::Asset Quantity)
instead of Sum (Assets::Asset Quantity) so that you only pull the Building types through.
ExecuteSQL
Finally, FileMaker 12 introduced the ExecuteSQL step. This may be the most elegant way to do the above because it doesn't involve changing any schema. The statement would be somethign like:
SELECT
SUM (Asset Quantity)
FROM
Assets
WHERE
Summary ID = ID AND
Asset Type = Building
For more information check out FileMaker's page: http://www.filemaker.com/12help/html/func_ref3.33.6.html
Also check out the FileMaker SQL Sugar ("#") Module for help building queries: http://www.modularfilemaker.org/2013/03/filemaker-sql-sugar/

FileMaker - How to have distinct values listed on-screen?

I would like to have the distinct values of a repeating field listed in another field (in browse mode). The case is as follows:
I have a field that contains country names. The country names in this field may repeat themselves, thus when using the "List" function I get something like "France, France, France, Germany, Germany, Hungary".
How can I create a field that lists all the values from my country field, but has it grouped as "France, Germany, Hungary"?
In the case I could directly use a SQL query to interfere with the FileMaker databse I would use the GROUP BY statement.
To make a summary of all the values across every record, do as follows:
Make a new value list labeled 'Countries' (File Menu > Manage > Value Lists)
Make the value list 'Use Values From Field' and specify your repeating field
Create a new Calculation field, 'Listed Countries'
Set the calculation to type 'Text' and with the following code:
ValueListItems ( Get(FileName) ; "Countries" )
If you'd like to find the value for only the current record:
Make a new Table Occurrence, 'NewTO' of the same base table and link the two records by a unique index.
Change the 'Countries' value list so that it obtains values from 'NewTO' and your repeating field.
Select 'Only include related values starting from' and select your original Table Occurrence
If you'd like the list to update as the repeating field value changes, make certain that you Do Not Store Calculation Results for the field.