Document Contents

The earlier parts of this document have focused primarily on the options available in a WordPage datasource, however, the real power of WordPage is in how it handles document content. WordPage takes ordinary text, including any formatting you have applied to it, and converts it to ASP code that executes on the web server. Anything that you want WordPage to treat as executable code is enclosed in curly braces {}.

Field References

The most common content processed by WordPage is references to fields retrieved from the database. A field reference consists of the datasource name a dot and a field name. Optionally, you can follow the field name by a colon and a total function. In the example above the fields referenced are CompanyName and Amount. For the Amount the total functions are all used as well.

 

The total functions that are defined as part of a field reference are calculated during the StartLoop…EndLoop processing. Their values are only accurate after the EndLoop command. The following table shows the available total functions.

 

Sum

The total for the field for all records

Min

The minimum value of the field

Max

The maximum value of the field

Avg

The average value of the field

Datasource Commands

Datasource commands consist of the datasource name followed by a dot and the command string. The example above shows the StartLoop and EndLoop commands being used the way they are most often used, at the beginning and end of a table, to display the results of the query. The available commands are:

 

StartLoop

The StartLoop command is used to begin a section of the document that will be repeated for each record returned by the query. It is most often used in a table to repeat a table row.

 

EndLoop

EndLoop ends the repeating section of the document that begins with StartLoop.

 

NoRecords

NoRecords is put near the end of the document if you want to create a special section of the document to only be displayed if the query produces no results.

Var.Page

Var.Page is a datasource variable that holds the number of the page currently being accessed in the result set. This is only valid if the datasource has a non-zero page size. To display the value the syntax is {=data.Var.Page}.

Var.PageCount

Var.PageCount is a datasource variable that holds the total number of pages in the result set. This is only valid if the datasource has a non-zero page size. To display the value the syntax is {=data.Var.Page}.

Var.RecordCount

Var.RecordCount is a datasource variable that holds the total number of records in the result set. If the datasource has a non-zero page size then Var.RecordCount may be accessed at any time. If the page size is zero Var.RecordCount is only valid after all records have been read.

NextLink

The NextLink command generates the URL that a hyperlink would use to jump to the next page in a paged result set. It should be used as the entire URL for a hyperlink.

PrevLink

The PrevLink command generates the URL that a hyperlink would use to jump to the previous page in a paged result set. It should be used as the entire URL for a hyperlink.

Expressions

Any content that begins with and equals sign (“=”) is treated as an expression. At runtime it is evaluated and the results are placed in the document.

Hyperlinks

Hyperlinks are created using either the datasource field list or using the “Insert Hyperlink…” command in Microsoft Word. For the purpose of creating a linked set of pages using WordPage the key is passing appropriate filter information in the hyperlink URL. There are two parts to the URL. The first part names the document to be loaded. The second part contains the parameters passed to the document. When linking to a WordPage document the parameters consist mostly of name/value pairs. The name must match a field name in the destination document. The value is the filter that will be used on the field in the destination document. Because WordPage processes items in curly braces { } inside the URL just as it does in visible document content the value can be a WordPage expression that retrieves information from the source document.

 

Let’s dissect a hyperlink to show how this works. Consider this URL:

 

            SomeDocument.asp?OrderId_flt={=data.OrderID}&Sort1=CompanyName

 

The pieces are:

           

SomeDocument.asp

This piece is the name of the destination document. Note that the name ends in ASP.

OrderId_flt

This chunk names the filter field. All filter fields end in “_flt”. This URL assumes that the destination document has a field named “OrderId” that accepts filters. Remember that “Allow filters in request” option in the Edit Query dialog allows you to control which fields allow filters. That choice must be made in the destination document.

{=data.OrderID}

This WordPage command inserts the value of the OrderID field into the URL.

Sort1

Sort1…Sort5 are parameters used in WordPage documents to define the sort fields. Sort1 is the first sort field.

CompanyName

CompanyName is a field in the destination document. In this case it will be the primary sort field.

 

Note: When editing a hyperlink you may see that the curly braces and spaces in the URL are replaced by things like %7b, %7d, or %20. This is the HTML syntax for representing special characters. It makes the URL harder to read when you’re editing, but is correctly processed by WordPage, Word, and the web server. When editing you are free to type in the curly braces and spaces wherever they are needed.

Filter Fields

When an HTML form is submitted to a web server the information on the form is passed in a way that is very similar to a URL. It consists of the names of each field on the form and the value that was entered by the user into the fields before the form was submitted. This capability is used by WordPage to make it easy to pass filter information to a WordPage document. To function as a filter the field name must match a field in the destination just like the hyperlink discussed above. The Field List makes it easy to create correctly named filter fields. If you need to edit the name of a filter field put the document into design mode, select the field, right click, and select “Properties”.

 

The syntax that your users can put in a filter field is discussed here.

VBScript Commands

When WordPage saves an ASP file it performs simple processing on any document content contained in curly braces. The text between the curly braces becomes the VBScript code that executes on the web server. The only significant translation that occurs is to change datasource field references and commands into appropriate VBScript source code. Text that is not recognized as a datasource field or command is passed through to the ASP document unchanged. Good ASP documents can be created using nothing more than the text generated using the field list. Authors with more experience can embed datasource field references in VBScript code to harness the full power of ASP. Here a some examples of using VBScript syntax along with WordPage field references.

 

Command

Purpose

{if data.Amount<5000 then}Danger!{elseif data.Amount>1000}Great!{else}That’s OK{end if}

Display different parts of the document depending on the value of a database field.

{for I=1 to data.Amount/1000}*{next}

Display a bar graph that represents the value of a data field.

 

More information about VBScript can be found here.

Stepping Through an Example

 

The example shown above illustrates most of the types of text that is processed in a WordPage document. This section explains each of the WordPage commands found in the document.

 

{data.StartLoop}

Begins a loop that will retrieve the records from the datasource

{=data.CompanyName}

Display the value of the CompanyName field

{if data.amount>6000 then}

Check the Amount field (which is a calculated field in this datasource). The portion of the document until the {else} will be executed only if the amount field is greater than 6000. This illustrates embedding a field reference in a VBScript command.

{=data.Amount}

Display the value of the Amount field. Note that all cosmetic aspects of the original Word document are preserved in the ASP document. This Amount value is displayed in green text.

{else}

Pair with the {if…then} and {end if} to mark the part of the document to include if the “if” condition is false.

{=data.Amount}

Display the value of the Amount field in black text.

{end if}

End the conditional execution begun by the earlier {if…then} statement.

{data.EndLoop}

Advance to the next record in the datasource and goes back to the StartLoop to continue.

{=data.amount:sum}

Display the total of the Amount fields across all records in the datasource.

{=data.amount:min}

Display the smallest Amount value found in the datasource.

{=data.amount:max}

Display the largest Amount value found in the datasource.

{=FormatCurrency(data.amount:avg)}

Display the average of all of the Amount values in the datasource. The FormatCurrency function is a standard VBScript function.