Servoy Advanced Programming Guide For FileMaker Developers

Introduction to a series of postings

Greetings from the Lake of Bays in the Muskoka lakes district on Ontario, where I’m reading the excellent document Servoy Advanced Programming Guide For FileMaker? Developers User’s Guide.

I’ve been making notes on points needing clarification, at least for me. I’m an experienced FMP developer and programmer, but have almost no background in any other programming environment. I find SQL as described in this document liberating. I look forward to putting the power of SQL to work with Servoy. This is exciting.

Because my notes have become so lengthy (so is the document I’m reading) I’ve chosen to break it up and post in a series of topics in this forum, each beginning with a page number from the source document in question.

I welcome comments and instruction. I don’t imply the document is inadequate in any way. It’s well written, well thought out, very worth reading. Think of this as questions from the student at the back of the class.

Two general comments. The first half of the document reviews SQL and JavaScript concepts, occasionally but hardly ever discussing FMP equivalents, thus making for very hard reading and understanding for the neophyte to these environments. The second half reverses itself, running down all the FMP script steps and functions, the Servoy equivalents, one by one.

In Chapter 4 with the introduction of JavaScript Objects I so badly lost my way I came close to abandoning ship. Objects are clearly an important concept, but without a clear foundation it proved nearly impossible to understand much of what followed. The definition of terms is terse to the point of tease, at least for this reader. I need context, examples, contrast, an explanation of the utility of Objects, what life would be like without them, etc. I have a general understanding of the overall concept, but has never had a programming environment to put them into practice. I’m still as clear as mud on this issue when it comes to the Servoy environment.

Page 20

<SQL databases usually do not store calculated values. In addition to columns whose values come directly from the database, a SQL query can include calculated columns whose values are calculated from the stored data values.>

I understand the first sentence, but the second one leaves me confused. Am I to understand that SQL calculations are made on the fly as needed, not indexed (ie stored) as in FMP? The following sentences in the same paragraph seem to suggest calculations are not stored as such as in FMP but are created each time required M-^W which seems awfully inefficient.

<To request a calculated column, you specify a SQL expression in the select list. SQL expressions can involve addition, subtraction, multiplication, and division. You can also use parentheses to build more complex expressions. Of course, the columns referenced in an arithmetic expression must have a numeric type. If you try to add, subtract, multiply, or divide columns containing text data, SQL will report an error.>

=====

Later on the same page is an example of a SELECT command to pull the number of the month from a “Date-Time” field. Which raises the question of how SQL stores dates. FMP stores the number of days since Jan 1, year 0001 (I believe). Which suggests SQL’s MONTH function calculates the month from the stored date. Assuming SQL uses a similar number of days from a fixed point in the past that FMP does. That’s a lot of assumptions. Are any of the above correct?

Page 24

A syntax question. In the following command taken from paqe 24, it would seem that either functions are distinguished from column names by being in all caps, or that functions are reserved, not allowed to be used for column names.

Comments?

In the following example, the word “like” is not capitalized, the only such difference noted on this and nearby pages. Is this an error or is capitalization irrelevant?

<SELECT Name, City FROM customers WHERE name like ‘%soft’>

=====

<4.4.6.3 Membership test M-^W Checks whether the clause of an expression matches one of a set of values. Example: SELECT Name, City FROM customers WHERE name IN (‘Servoy’, ‘Bob’)>

The example is as clear as mud, to me.

Similarly unclear is the Pattern Matching test example. The explanations merely state the command is available without explaining the syntax in sufficient detail to be unambiguous.

=====

Later on the same page is this mysterious statement:

<In a SQL database, there is a difference between an empty field (containing nothing) and a NULL field. NULL can be seen as a special nonexistent value.>

No explanation (at least on this page) on what a “special nonexistent value” might be. Anyone have some clarifying examples?

Page 25

Because the LIKE function wasn’t clearly explained earlier, the following command on page 25 doesn’t make much sense, at least to me.

<SELECT productname, price FROM Products WHERE price > 80 OR productname LIKE ‘%a’>

I don’t see any records in the results shown that align as being “like ‘%a’”. Comments?

=====

Page 27

There’s a discussion about multi-table queries (joins). It gives the example of

This is the first introduction of the dot or period as a separator, but by no means the last. In fact the convention of term.term is quite common in both SQL and JavaScript.

I’d be far happier if there were a general discussion of this syntax, how to read, understand and use it. There’s no comment about it in the accompanying text.

Way later in the text this convention of dot separators seems to be the first term is a Servoy reserved word followed by the argument. For instance: <forms.order_details.elements.firstName.selectedText();>

In other environments I would expect arguments to be enclosed in parentheses, which leads to my surprise at this convention. Here there are both dot separations and also parentheses. Some discussion would seem to be in order. I’d like to have this syntax down cold.

Page 28

The concept of Aliases is introduced. But the examples used seem more to be the declaration of variables on the fly. Is this just semantics, or are variables = alias in SQL?

<Here’s the query using column aliases in front of the fields:
SELECT A.CompanyName, B.OrderID, B.OrderDate
FROM Customers A, Orders B
WHERE A.CustomerID = B.CustomerID>

=====

<4.5.1 Matching multiple columns>

is breathtaking in its implications, at least for this FMP developer who has long been held in by the constraints of FMP. This is an excellent example of the flexibility and frankly, the simplicity of SQL.
Page 37

=====

Page 42, declaring variables

These sound like FMP globals, except they can be created and instantly used.

Questions:

M-^U are there types of variables in the same way as there are types of globals in
FMP? Or can any variable hold a date, a time, a number, a container, etc?

M-^U since variables can be created anywhere in the code, it sounds like a programmer could, in error, use the same variable name as elsewhere unintentionally, thus overwriting an already declared variable by the same name. Is there a facility to prevent this happening unwittingly?

M-^U FMP’s globals have the interesting characteristic of being true for the current user, not universal. Thus I can create a global gUserName and store the current user’s name. Any time I use this global I’m sure to call up the current user’s identity, none other. Is there a facility for this in Javascript. Page 42 doesn’t seem to discuss this aspect.

Later on Page 50 there’s a discussion of “weak typing” under section 5.3.3.3. I’m assuming this is an answer to my first question above. Confirmed? I’ve yet to see an answer to the other two.

=====

Page 44

<var x, y = 2, z;>

Am I correct that this example of declaring several variables in a single statement is also bad style? Only the y variable has content. The other two are null. Comments?

Page 47 Boolean data types

<Undefined data type
The undefined type is used for variables or object properties that do not exist; or have not been assigned a value. The ONLY value an undefined type can have is undefined.
Example:
var x;
var x = String.noSuchProperty;

Sorry, this makes no sense at all. And even if it did, why would I want such an animal?

=====

Page 48

The Null data type is introduced. Is this just the same as a variable with no declared value, not even empty? Or is a Null data type a distinct entity to itself? I suspect I’m lost in a thicket. We started out talking about numbers and text data types, but now we’re dealing with some exotics.

This one is major.

Page 54-55 introduces Objects but the description and examples here are terse to the point of tease. This sounds like a particularly powerful tool in a Servoy environment. The sections on Properties, Functions and Methods are similarly sparse and, for this reader, simply cloud the issue rather than clarify. These terse statements are essentially repeated, almost word for word, on pages 59-60 without any further enlightenment.

Can someone point me to a fuller description and explanation of these fundamentals, either within this same document or elsewhere? I’ve read much further and a glimmer of uncertain understanding is beginning to arise, but I’m still very wobbly on these critical concepts. Clarifications and guidance appreciated.

Page 67 says

<For example: s2 = new String(“foo”); // creates a String object.
String literal
Do not confuse a string literal with the String object.
The following code creates the string literal s1:
s1 = “foo”;>

Which leads me to start to think of Objects as equivalent to Variables, different ways of doing the same thing. But that can’t be right since so much emphasis is being put on Objects. No, I don’t understand at all, beginning with that extremely spare introduction to Objects on page 54.

It’s at this point in my reading I start to skim, searching for the gist of what’s being described. I’ve lost the thread.

=====

Page 125

Beginning with 5.7 JavaScript Flow Controls I’m back on track. This is very different from FMP’s rather limited Loop script steps and exciting, offering much greater flexibility, and frankly more readable than the complex nested loops we’ve had to write in FMP.

Page 129

The following description of the JavaScript IF statement sounds suspiciously like FMP’s Case statement. True? The ElseIf structure, while more verbose, seems very like the Case statement. The Switch function seems even close to Case.

FMP’s nested If statements are a terror, virtually unreadable. Thus we abandoned If for the clarity and simplicity of FMP’s Case statement in all circumstances.

<The expression is evaluated; if the condition is true, then the statement is executed; otherwise it moves on to the next statement.>

=====

Page 145

<Reserved words cannot be used as JavaScript variables, functions, methods, or object names. Some of these words are keywords used in JavaScript; others are reserved for future use.>

Question:

Is there automatic error trapping in Servoy to trap for inadvertent use of reserved words?

Page 167

The very commonly used FMP Halt Script step apparently has no Servoy equivalent, but there is an Exit function. Exit merely exits the current script and continues processing whatever other outstanding scripts are in process. Halt stops everything dead in its tracks.

If there is no Halt Script function in Servoy, one wonders what a FMP to Servoy conversion tool would do translating FMP code? It seems odd there is no way of stopping everything. If not, why not? What are the programming recommendations for this situation? A commentary on this situation would seem to be in order.

=====

Page 178

FMP Set Error Capture → Servoy application.setErrorCapture(boolean)

If this function is only available within Servoy Developer, what is the client’s experience when an error is encountered?

Within FMP we attempt to always trap for error possibilities with our own messaging instead of FMP’s often confusing and overly terse responses to errors. For instance, if the client ends up in a situation we don’t believe ever could be possible, we nevertheless display our own error message as a safety precaution. Such messages typically will name the script, the file and the error number with a request to the user to notify us. In practice end users rarely encounter them, but we definitely do in beta testing. The above limitation on Error Capture to Servoy Developer only would suggest our beta testers should always be running Developer rather than Client.

Comments?

=====

Something called “Controller” is introduced on Page 178 and then used repeatedly on following pages M-^W but without explanation. From the context I can get the sense of how to use it. But what exactly is it?

Page 180

Go to Related Record (GTRR) becomes <forms.detail.controller.showRecords([relationName])>
in Servoy.

GTRR is a very important command for us in FMP and actually comes in two forms M-^W go to the first encountered related record or show only related records.

The accompanying text doesn’t explain the Servoy syntax very clearly. Particularly puzzled by the term “detail”, and again by that word “controller”.

Then there’s that other issue of the “Show” condition of GTRR. What’s the syntax for that?

We frequently invoke Show GTRR just before jumping to a layout, or before running a loop. But there must be dozens of different ways we use this very useful command. I need much greater clarity on this one, please. Comments?

=====

Page 183

Goto Next Field and Goto Previous Field are not currently supported. Which raises the question M-^W is tab field order supported in Servoy? Can’t imagine it wouldn’t be, but haven’t seen it mentioned yet.

Page 186

Would be helpful to show a screenshot or two of the Sort dialogue in the midst of the discussion of sorting options. I’d assume the sort dialogue is customizable. Right?

Unsort is not available. Would the same effect be rendered by doing Servoy’s equivalent of GTRR on the current relationship (if any), a relationship to the constant field, or use loadAllRecords?

=====

Page 198

Insert from Index not currently available in Servoy. Question: is there a way of displaying the index of a field? Is not, is it high on Servoy’s wish list? For end user searching, we currently present the user with a display of fields with accompanying buttons for which present the index for the field. It’s a fairly efficient and intuitive search technique. Comments?

=====

Page 204

The deleteRecord() command doesn’t have FMP’s warning dialogue/no warning options, right? User warnings I assume need to be created as needed. No problem.

Page 207

<copyAllRecords()>

One of the weaknesses of FMP is the limit on how many records can be copied by this command. Are there any limits to this command in FMP?

For FMP’s Replace command Servoy recommends a loop with this note:

<NOTE: For replacing a value (updating) in a very large foundset of records, we recommend that you close Servoy Developer and run the update using a SQL tool directly on your SQL backend database.>

Within FMP, generally the Replace command is faster than doing a loop. Am I right to assume that a Servoy loop is sufficiently fast to not frustrate the end user? At what foundset of records is
it recommended to use a SQL tool directly instead?

=====

Page 210

Import and Export are NOT supported by Servoy!!! Really? This is remarkable in a product that’s come out of beta. No comment on how to get legacy data in and no guidance on getting client data out??? In the works? A workaround? Comments?

No Freeze Window and Refresh Window commands? Because they’re not really necessary in Servoy? Or just not yet created? In what sense is <application.updateUI()> different from refreshing the window?

Likewise no Scroll Window, Toggle Window and Toggle Status Area. Safe to assume these are in the works?

Page 219

What are the limitations and flexibility of the Servoy showDialog() command? How many buttons, how many input fields? Radio buttons, check boxes? Dialogue size limitations? Control over placement of labels, fields and other elements in dialogues? It would be helpful to show some dialogue screenshot examples here. This is a very important matter for a designer paying close attention to user interface.

=====

Page 225

Send AppleEvent. We’d like to have our solutions automatically interact with other Mac programs. Likewise with Windows equivalents. Is this in the works?

=====

Page 229

No quit or exit application command? Really?!!

=====

Page 273

If there is no Servoy equivalent to FMP’s Get Summary function, what is the recommended workaround?

=====

Page 297

Is that right, only four possible sources of error when running <application.getLastErrorCode()>

Good news if it is.

<
1 Connection with server lost.
2 Record is locked.
3 Invalid input.
4 JavaScript error.

Page 295

The Servoy equivalents of Status(CurrentFoundCount) are apparently expensive in processor time. The Status(CurrentFoundCount) command is very common in our solutions, often to identify if there are any records currently selected or whether the count is above a particular number.

Some guidance on these issues would be helpful.

=====

Page

An equivalent of FMP’s Status(CurrentLayoutNumber) is not available within Servoy

In FMP we use this function to store in a global so that we can return to that specific layout at a later stage in a script sequence. We use this specific Status function because it’s reliable in FMP. We don’t like the idea of hardwiring in a layout’s name into a script when it could later be changed, thus introducing a bug into our routines.

What’s the situation in this respect within Servoy? Recommendations?

=====

Page 309

Status(CurrentUserCount) is not available in Servoy. However, we currently use this FMP function to control authorized licensing of our solutions. They’re licensed for so many machines. If they exceed the licensed count at any given time, the additional users are bounced off.

Is there a Servoy equivalent for this control?

=====

Page 313

We currently use the FMP design function of ValueListNames in order to prepare an index of a field. This index is then used in a dialogue to give the end user some valid choices. Neither ValueListNames nor Indexing are currently included in Servoy. What’s the workaround?

This is the last of a series of 14 postings raising questions about this document.

Thanks for your extensive feedback, it will help us to improve this book a lot. I will try to reply to all of your questions below.

Two general comments. The first half of the document reviews SQL and JavaScript concepts, occasionally but hardly ever discussing FMP equivalents, thus making for very hard reading and understanding for the neophyte to these environments. The second half reverses itself, running down all the FMP script steps and functions, the Servoy equivalents, one by one.

Is that good or not? The idea is that you get an overview of SQL and JavaScript first and then start comparing this new knowledge to Filemaker. Did we achieve that? or not? How can we improve?

In Chapter 4 with the introduction of JavaScript Objects I so badly lost my way I came close to abandoning ship. Objects are clearly an important concept, but without a clear foundation it proved nearly impossible to understand much of what followed. The definition of terms is terse to the point of tease, at least for this reader. I need context, examples, contrast, an explanation of the utility of Objects, what life would be like without them, etc. I have a general understanding of the overall concept, but has never had a programming environment to put them into practice. I’m still as clear as mud on this issue when it comes to the Servoy environment.

We will consider adding an introduction to objects as well. There are however already many, many publications that cover that so I’m not sure that should be covered by this book.

==Page 20==

You suggest calculations in SQL databases are inefficient, this is not the case in most of the situations. Only if you search frequently for a calculated value this may become an issue. Keep in mind that SQL databases calculated much and much more efficient than Filemaker Pro. If you do need to search frequently for certain calculated values there are still several approaches in SQL to achieve this, all of these are not relevant in Servoy as Servoy does offer both stored and unstored calculations and takes care of the SQL processing that that needs.

Most SQL databases store date and time (just like operating systems and programming languages) in one field. In general the amount of miliseconds that have passed since 1-1-1970 are stored, as this can also be a negative number you can also go in the past.

==Page 24===
capitalization is not relevant in SQL as indicated on page 19, in general you do type the SQL reserved words in ALL CAPS to make your query easier to read.

WHERE name IN (‘Servoy’, ‘Bob’)

THe above is called a membership test, it searches in the field NAME for the values “Servoy” or “Bob”
In Filemaker you perform a membership testing by searching for multiple values in the same field, separating them using the ‘New Request’ command.

Pattern Matching is used to match parts of a string. The % sign matches one or more characters.

NULL is value that doesn’t exist, the reason that it is described as special is because databases treat it differently using searches. It is impossible to give an example of NULL as it doesnt exist. It goes beyond the scope of this sql introduction to dig deeper into it, for more details a SQL introduction book would be a good purchase.

We’ll try to compare searches more with Filemaker searches.

== page 25==
productname LIKE ‘%a’ means, productname ends with small a. a couple of them are returned as you can see.

== page 27==
the dot syntax is generally used to dig down a object tree, you could see a table-column structure as an object structure therefore saying:
table.columnname. In JavaScript and other OO languages this is a common way to refer to objects. Other than this there is not much to say about it. Parenthesis are used to pass arguments, arguments are never passed behind a dot.
== page 28==
All an alias in SQL is is a different way to name an element. It’s not a variable just an ‘on the fly’ renaming of a column.

== page 42==
Variables are just like Filemaker Pro globals, a place to hold a variable and only valid on the computer where executed. They are only valid in the current method (fmp: script) where they are executed. Servoy also has Global Variables that are valid accross an entire solution (as opposed to FIlemaker where they are only valid in one file)

Variables can contain anything in JavaScript. It can even change from type on the fly, this is called weak typing.

In JavaScript it is possible to overwrite variables. It will not warn you if you attempt to do that. Basicly that is the same as overwriting a Global in Filemaker Pro. As with any programming language: Know what you are doing.

JavaScript variables are just like FIlemaker globals only valid for the current execution.

== Page 44==
The demonstrated example just shows you CAN declare multiple variables at once even initializing some to NULL. In general it is good practice to declare them on separate lines to improve readability

== Page 47==
Sometimes you want to initialize a variable to used it further onwards, you can leave it undefined when you declare it to use it later.

== Page 48==
NULL means it doesnt exist. Basicly undefined is also NULL but somehow the JavaScript creators decided to give it a separate name as well.
A variable that has not been assigned a value is of type undefined. A method or
statement also returns undefined if the variable that is being evaluated does
not have an assigned value.
You can use undefined to determine whether a variable has a value.
In general I tend to use NULL everywhere as that is also the way used in Java and SQL

== Page 54==
You can find a very short but clear description of Object here:
http://headcase.case.syr.edu/welcome/In … page3.html

== Page 67==
Objects can be variables. Objects can have properties and functions.
There are many introductions to Object Orientation out there, for example:
http://www.futureobjects.de/content/intro_oo_e.html
Alternatively do a search in Google and check which introduction works best for you.
== Page 145==
Yes, Servoy traps for usage of all reserved JavaScript word as well as reserved Servoy words and reserved SQL words
== Page 167==
Servoy will support Halt in the future to be able to support converted scripts. It is not recommended to use Halt both in Servoy and in Filemaker. It’s better to program your scripts/methods correctly
== Page 178==
That’s an error in the manual. setErrorCapture is also available in Servoy Client.
== controller==
The controller controls the current form. It’s the object that can manage all form actions such as: new record, delete, sort, find, etc.

Morley – Two general comments. The first half of the document reviews SQL and JavaScript concepts, occasionally but hardly ever discussing FMP equivalents, thus making for very hard reading and understanding for the neophyte to these environments. The second half reverses itself, running down all the FMP script steps and functions, the Servoy equivalents, one by one.

Jan – Is that good or not? The idea is that you get an overview of SQL and JavaScript first and then start comparing this new knowledge to Filemaker. Did we achieve that? or not? How can we improve?

I’d recommend a paragraph off the top outlining where you’re going. For the neophyte to SQL and JavaScript (me), it would help to draw parallels and contrasts to the already known environment of FMP (the audience this document is intended for). I would argue that all developers migrating from FMP to SQL and JS will need to be conversent with the contrasts in any case. So it would help to make them as issues are raised.

Morley – In Chapter 4 with the introduction of JavaScript Objects I so badly lost my way I came close to abandoning ship. Objects are clearly an important concept, but without a clear foundation it proved nearly impossible to understand much of what followed. The definition of terms is terse to the point of tease, at least for this reader. I need context, examples, contrast, an explanation of the utility of Objects, what life would be like without them, etc. I have a general understanding of the overall concept, but has never had a programming environment to put them into practice. I’m still as clear as mud on this issue when it comes to the Servoy environment.

Jan – We will consider adding an introduction to objects as well. There are however already many, many publications that cover that so I’m not sure that should be covered by this book.

A paragraph or two of intro, plus URL links to other sites and books for further reading, is probably all that’s required. In fact, links for further learning throughout would be highly recommended.

Jan – WHERE name IN (‘Servoy’, ‘Bob’) THe above is called a membership test, it searches in the field NAME for the values “Servoy” or “Bob”. In Filemaker you perform a membership testing by searching for multiple values in the same field, separating them using the ‘New Request’ command.

An example of a contrast to FMP that would be helpful as we unlearn assumptions and take on new concepts.

The more I dig into it, the more I’m impressed with Servoy and its approach to SQL. Much thanks for the clarifications.

== page 180==
Servoy only has one form of goto releated which does exactly what it says, it shows related records, nothing more and nothing less.

We frequently invoke Show GTRR just before jumping to a layout, or before running a loop. But there must be dozens of different ways we use this very useful command. I need much greater clarity on this one, please. Comments?

What else would you like to know about it?

== page 183==
Taborder is planned for future versions.

== page 186==
What do you mean with sort dialog is customizable?

To unsort use loadAllRecords

== page 198==
Show index is a specific Filemaker function that is not available in Servoy. First of all most SQL environments don’t allow you to retrieve the contents of an index, secondly most SQL database index per column as opposed to Filemaker which indexes per word. There are many other ways in Servoy to help users search for data, keep in mind that in Servoy you have navigation panels to help navigation and search as well as popup forms that you can design to offer fast searches with much greater flexibility. Lastly you also have full SQL access to any datasource for even greater flexibility.

== page 204==
deleteRecord doesnt warn currently, there are plans to add that though.

== page 207==
The amount of rows is only limited by available memory.

Servoy loop is much faster than Filemaker’s loop. For VERY big replaces we still recommend executing an update statement directly on the backend database.

== page 210==
Import Records/Export is not available as a method step. You can do export and import using dialogs or write directly data to a file (using a method to gather the data). Import and export through methods is planned for a future version.

Servoy always freezes the window during method. If you explicitly want to refresh it use updateUI(). Much easier than Filemaker Pro.

We don’t have scroll window at this time.

Toggle window is not relevant as Servoy has an SDI (Single Document Interface). The status area can not be changed at runtime (only in designer)

== page 219==
showdialog only does very basic dialogs. For more controll use showFormInDialog, with that function you can pop a form into a dialog giving you ALL the flexibility (design, scripts, events) you could ever need.

== page 225==
you can use executeProgram to accomplish that

== page 229==
As of Servoy 1.1.1 that command is now available

jaleman:
Servoy will support Halt in the future to be able to support converted scripts. It is not recommended to use Halt both in Servoy and in Filemaker. It’s better to program your scripts/methods correctly

Here’s how we’re currently using the Halt command within FMP. I’d be curious to know an alternative.

Because the Mac OS supports zoom, as control is shifted from file to file, open windows of other files appear underneath. Therefore we’ve created a utility script which calls a Hide command in the other files, then calls Halt.

When we make a call to an external script that transfers control, we follow it up with a call to that file’s Halt Script which also ensures the user is left in the target file, not dangling in the originating file.

I would assume within a Servoy environment calls to such Halt Scripts would not be required.