ValueList from ExecuteSQL() based query in FMP 12 - filemaker

I'm looking into upgrading our FMP11 developed solution to FMP12. For us, key functionality exists around the ValueList feature to DISPLAY one value (e.g. a description) while RETURNING another value (e.g. a UID), into the selected field.
I would be interested if you have been able to replicate this feature from the ExecuteSQL() function (I can successfully return a single ValueList ... having trouble with the above)
many thanks in advance
Giles

Based on the core functionality of value lists, you can't use the ExecuteSQL() function to calculate the value directly inside of the value list dialog box.
What you would have to do is create a table with a single record and two fields. Then you would use an ExecuteSQL() calculation to populate the first and second fields with data. It would be important to make sure you sort your data inside executeSQL() in the same order in both fields.
So your filemaker calculations would be (assuming the first field is key and the second is name and it's from a table called items, and you are looking for where key > 100)
keylist =
ExecuteSQL (
"SELECT key
FROM items
WHERE key > 100
ORDER BY key ASC"
; "" ; "" )
namelist =
ExecuteSQL (
"SELECT name
FROM items
WHERE key > 100
ORDER BY key ASC"
; "" ; "" )
You would then create a value list that uses keylist as the first field, and namelist as the second field, only displaying values from the second field.
It would be nice to have the functionality to calculate a value list, but as far as I know filemaker always needs to pull values from a source outside of the value list dialog box.

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 value validation against value list

Need to validate values within a field against Value List, retaining the value if on list but substituting a specific Value if not?
I am afraid you are mixing two separate things:
Validation checks if some conditions have been satisfied; if not, it throws an error. It will not correct the entry.
If you want user entry to be corrected, you need to either:
define the field to auto-enter a calculated value; or
attach a script trigger to it, and have the script modify the value entered by the user.
In this case, you could auto-enter a calculated value (replacing existing value) =
If ( IsEmpty ( FilterValues ( Self ; ValueListItems ( Get (FileName) ; "YourValueList" ) ) ) ; "Specific Value" ; Self )
--- Added in response to your clarification ---
Technically, you could run a script to find the records you want to verify and do Replace Field Contents (using the same calculation) on that field. You could run the script after changing the value list, as part of the weekly routine.
However, there are two major problems with this approach:
some records could be locked by another user;
you have no history of what happened, and no way to go back in case of making a mistake.
I also don't think it's good practice to have users modify a value list routinely. If you need to have a weekly list of values, you should store them in records, not in a value list. That way at least the part of the value list would have a history.
Another option you may consider is using an unstored calculation field with a similar formula. This would change dynamically with the value list, and leave the original field unmodified. This would be a good arrangement if, for example, you need to export the corrected values every week.

Relate text to Id once selected from text box with suggestion option in rcp

I currently have a text box that can predict String as typed.I used the snippet here .
There are two seprate questions
Q1)In the snippet the suggestion are passed as item but I want to relate the String to an id to update the database. If I just pass the string to snippet I need to do another query to again retrieve the id which costs resources is there a way to pass objects to the auto suggestion which will select the id of whichever name is chosen from the suggestions.
Q2)Also I dont want user to be adding new values so is there a way to force user to chose one of the values from the suggestion for the text box and not add his own values
This might be a workaround for your Q1.
In the auto-complete shell , use a SWT Table instead of combo widget.Have two columns in the table for string and string Id.Hide the second column so that the user cannot see it.You can use this column to retrieve the ids of corresponding strings.
Or simply store the string and string ids in a hash map and give the key values set of this hash map to the combo items.

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.

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.