Login    Sites MenuBlueStep

BlueStep Platform Support

RelateScript
Outline full outline 
Overview 
Data Types 
Operators 
Statements 
Functions 
Working with Relate Data 
Field Data 
Accessing Forms and Fields 
Accessing Fields 
Single Entry Forms 
Multi-Entry Forms 
Queries and Reports 
Searching 
Form Permissions 
Special Data and Functions 
How Formulas Work 
Related Topics 

In the case of a multi-entry form it is not sufficient to simply identify the form and field you are interested in.  You must also identify which entry is desired.  This is done using the standard array syntax following the form id.   The complete syntax is:  the form's identifier, an opening square-bracket, the index value, a closing square-bracket, a period and finally the field's identifier.  The entries are numbered starting at zero and counting up until the last entry.  To specify you want the first entry (at position 0) you would write:

formId[0].fieldId

This rule is followed when accessing any data of a multi-entry form, except in three cases.  1. Field formulas, of course, are only concerned with a single entry of a single form, even if the form happens to be multi-entry.  2. If the primary form of a formula is a multi-entry form then the current entry, or primary entry, is a single entry.  In either of these two cases single entry form data and multi-entry form data are accessed in the same way.  In field formulas the field identifier alone is sufficient.  In other types of formulas the form identifier, a period and the field identifier are used.  3. The third and final case is the special System field.  Even an array of entries constituting a mult-entry form has a System field which may be accessed on individual entries or on the list as a whole.  When accessed from the list, certain properties will be empty, such as the viewURL property.  However, many properties of the System field will be the same for either the array of entries or an individual entry.

The last thing to know about accessing data in multi-entry forms is that it isn't necessary to always work with the full list of entries in the default order.  A multi-entry form report may be used change the order of the entries or eliminate entries not needed by the formula   A multi-entry form report may define search criteria to eliminate unwanted entries from the list, and sort criteria to change the order of the entries in the list.  The display columns of the multi-entry form report do not affect the data available to the formula.  This feature can prove invaluable in reducing the amount of work to be done by the formula.  For instance, to find the largest amount in any entry, a multi-entry form report could be used to sort the entries by amount.  Then instead of searching through the whole list to find the largest amount, the lastIndex(...) function will grab the last entry from the list produced by the report.  In some cases you may even want to access the same form using multiple lists defined by different multi-entry form reports.

Not only can multi-entry reports specify search and sorting, but also search and sort may be specified within the formula.  By calling special functions you can add additional search criteria and override the sort criteria in the same way the user can while viewing a query.  For multi-entry reports with search criteria based on the current date, a formula can request that the query run as though the current date/time is different.  This allows viewing the report as it would have looked in the past or as it will look in the future, assuming today's settings and data.  Finally, in a merge report these overridden search and sort settings may be 'remembered' thus altering the view of the same multi-entry report displayed in the merge report.  A summary of these features, and a description of how these functions work is given in the table below.

 

Field/Function Description
System This field of a multi-entry form object is similiar, in most respects, to the System field of the individual entries or of a single-entry form. Additional information may be found in the article titled "System Data."
addSearch(fieldId, operator, value)

Adds a search to the current list of entries.  The fieldId is a String value containing the formula id of the field, not its name or label.  For additional information on the operators and values that are appropriate for different types of fields, see "Searching."  Search criteria are in addition to, not a replacement of, any search criteria specified in a multi-entry report.  If multiple search criteria are added, only entries meeting the requirements of ALL the search criteria will be returned in the results.  The result of the addSearch function is a String value which will be null if a valid search criteria is defined by the function call.  If the String value is not null, it will contain a message indicating what is wrong.

addSort(fieldId) Adds a sort to the current list of entries.  The fieldId is a String value containing the formula id of the field, not its name or label.  Sort criteria override any sort settings specified in a multi-entry report, but they do not override any grouping settings, which also have the effect of sorting the entries.   In otherwords, it will sort within the groups.  If multiple sorts are added it will search first by the first sort specified, and next by subsequent sort criteria.  A maximum of three levels of sorting are allowed, including sorting caused by grouping.  The result of the addSort function is a String value which will be null if a valid sort is defined by the function call.  If the String value is not null, it will contain a message indicating what is wrong.
anchorTimestampSearch(timestamp) For multi-entry reports with search criteria based on the current date/time, causes the report to run as though the current date/time was timestamp.  This can be used to view the results of the report as they would have looked in the past or as they will look in the future, assuming today's data.  The result of this function is the prior value set, if any.
clearSearchAndSort() Clears any search criteria, sorts and timestamp anchor which may have been previously set.  Also, resets the remember feature.  The result of this function is true if search or sort parameters were actually cleared by the function.  The result is false if the function did not have any settings to clear.
rememberSearchAndSort() For formulas that are part of a merge report, calling this function causes any current, or future, search and/or sort critieria to be remembered and used when displaying the same multi-entry report in the merge report.  This also works for the '[all entries]' report.   This function should only be called from a merge report formula.  Calling it from other types of formulas will have unpredictable results possibly including storing bad data in Relate.  This function results in a boolean value which indicates whether calling the function had an effect.
getById(id) Gets a specific entry directly, by id.  This is useful for params fields and other cases where there is stored id.  This function will not allow any entry that is not a part of the query result (before applying additional search criteria) to be retrieved.
getCurrent() Gets the current or primary entry of the multi-entry form.  A multi-entry form may have a primary or current entry in two cases.  1. The first case is when the formula or merge-report has a primary form.  If the primary form is a multi-entry form then the formula or merge-report runs on a particular entry of that form.  The entry that the formula is running on is the primary or current entry.  2. If working with a query or report in-formula, the query or report may have search or display fields from a multi-entry form.  The result of such a query or report will have  a current or primary entry of that form for each row of the result.

 

Example:  In most cases, it will be necessary to perform some operation on each of the entries of the multi-entry form.  In this case a loop is needed.  There are several ways to accomplish this.  The easiest loop in this case is a for/in loop.  For instance, if a multi-entry form with an identifier of "myMultiEntry" has a numeric field "amount" and the total amount of all entries is needed, use the following:
    total = 0.0;
    for (index in myMultiEntry) {
        total += myMultiEntry[index].amount;
    }

In this example, "index" is just a normal Integer variable--any name could be chosen.  Each time through the loop, the value in the variable "index" will advance by 1, starting at 0 and proceeding until all entries have been processed.

Example: Other types of loops may also be used.  In the above example the second line could be replaced with
    for (index = 0; index < myMultiEntry.size(); index++) {
with exactly the same result except more typing.  This type of loop can be useful, however, in several situations.  If the sum of only the first 10 entries is needed it is easily accomplished by modifing the same line to read:
    for (index = 0; index < 10; index++) {
Also, in some cases you may need to loop through the entries in reverse order.  This type of reverse loop can also be done with another variation on the same line:
    for (index = myMultiEntry.lastIndex(); index >= 0; index--) {