问题
I am building a system using Starting Point and need help with calculated fields.
Basically when an estimate is created it takes the same ID as the project its linked to with a "-1" 1 being incremental value. So if the increment -1 exists the next estimate for that project would be -2 and so on.
So for example
Project Id: 120000
First Estimate: 120000-1
Second Estimate: 120000-2
I have found out how to add a hyphen and number after the project ID (the stored as estimate ID) like so id_project & "-" & 1
but I have no idea using filemaker how to use calculated fields to look and see if 120000-2 is a thing and if it is make it 120000-3
Any help greatly appreciated
回答1:
I'm assuming you have at least a relationship between Projects and Estimates. Perhaps something like this (without the Estimates_self table occurrence, which I'll get to in a moment):
If you're in the Projects context (on a layout linked to the Projects table), you can get a count from there using something like Count ( Estimates::id )
.
If you want to make this happen from the context of Estimates, create a self-join as shown above, using the project foreign key as the match field. Then you can use Count ( Estimates_self::id )
.
Finally, an option without any relationship graph changes would be to use ExecuteSQL
:
ExecuteSQL (
"SELECT COUNT(*) FROM Estimates WHERE project_id = ?" ;
"" ; "" ;
Estimates::project_id
)
All of these will give you the number of estimates that a given project has. Add one to that and you have your suffix number for the new estimate.
回答2:
Count the related estimates based on a parent Project. This will give you the Estimate number after dash
来源:https://stackoverflow.com/questions/47472956/calculated-fields-and-increments