Accessing Forest and Trees from an ASP page using OLE Automation
search cancel

Accessing Forest and Trees from an ASP page using OLE Automation

book

Article ID: 56070

calendar_today

Updated On:

Products

Cleverpath Reporter

Issue/Introduction

It is possible to use Forest & Trees to store and/or retrieve data from an FTV with OLE automation via an ASP page. The scope of this article is to provide a general overview of using OLE Automation on an ASP web page.

 

Environment

Release:
Component: FTS

Resolution

The simple example ASP application below can be used to store an inventory of items and calculate and retrieve a graph from Forest & Trees.

The files that are used in this demonstration can be downloaded from here:-

 

Requirements

  • Forest & Trees with the OLE Automation Server Add-in installed (FTWAUSVR.FXA)
  • IIS

Preparing the FTV

Create a table view with 'Formula' interface and call it inventory_totals.

Enter the initial formula for this view as

Calculate the view. Using Column layout, change the COLUMN1 caption and title to 'item' and the COLUMN2 caption and title to 'amount'.

Create a default graph as follows, click Ok.

Name it 'Inventory', click OK.

Accept the defaults that appear, click OK.

On the toolbar, Click the Pie chart button.

Right click the graph and click, Annotations, Text. Then modify the Point Labels as shown.

You may want to add further formatting to the graph at this point, but this is beyond the scope of this article.

Click the Fast Exit button.

Now that the column titles and graph have been defined, change the view definition of 'inventory_totals' to a view with 'No Interface'.

Now save the FTV in a folder and call it inventory.ftv.

Using ASP to access the FTV

We use the ASP page to write new values to the inventory_totals view within inventory.ftv. The graph is then redrawn and the image is exported to JPEG file which is then displayed on the web page.

The full source of the ASP page, inventory.asp, is listed below but here is a description of the significant VB Script code fragments.

Dim ftobj Set ftobj = Server.CreateObject("Forest.Trees.Application")

This creates the OLE Server object, once this object is instantiated all Forest & Trees automation methods can be executed.

The FTExecuteFormula method allows the execution of any F&T function externally.

ftobj.FTExecuteFormula "<F&T function>"

This function is used to open the FTV file, add the new values, to export the graph, to discard the data and to save the updated file. There are many other F&T Methods for automation and these are described in the F&T help file.

Set ftobj = Nothing

This closes down OLE Server object.

Place inventory.asp into the same folder as inventory.ftv.

IIS Setup

Create a virtual directory in IIS and call it inventory and point to the folder where inventory.asp and inventory.ftv reside.

Setup the virtual directory to Enable Content Expiration immediately as follows. This is necessary because the default behaviour of IIS is to cache images, so the updated graph image would be displayed unless the content of the virtual directory expires immediately.

'inventory.asp' Source

<%@ Language=VBScript %>
<html>
<head>
<title>Inventory F&T OLE Server example</title>
</head>
<body>
<%
   Sub RecalcInventory (item, amount)
      Dim ftobj

      Set ftobj = Server.CreateObject("Forest.Trees.Application")

      app_path = Request.ServerVariables("APPL_PHYSICAL_PATH")
      
      'Open FTV file
       ftobj.FTExecuteFormula "File('open';'" & app_path &
"inventory.ftv')"
       
       'Set autosave with no prompting
       ftobj.FTExecuteFormula "File('SetAutoSave';1)"
       
       If (item <> "") And (amount <> "") Then
          'Add new value to view
          ftobj.FTExecuteFormula "View( 'AddValue',
'inventory_totals', '" & item & "', " & amount & " )"
       End If
       
       'Calculate View
      ftobj.FTExecuteFormula "View( 'Calculate',
'inventory_totals' )"
      
      'Draw graph
      ftobj.FTExecuteFormula "Graph( 'Calculate',
'inventory_totals', 'Inventory' )"
      ftobj.FTExecuteFormula "View( 'Paint', 'inventory_totals' )"
      
      'Write graph to jpeg file
      ftobj.FTExecuteFormula "Graph( 'Export',
'inventory_totals', 'Inventory', '&thisAppPath&inventory.jpg', 'JPEG'
)"
      ftobj.FTExecuteFormula "File('new')"

      Set ftobj = Nothing
   End Sub
   
   Sub DiscardData
      Dim ftobj

      Set ftobj = Server.CreateObject("Forest.Trees.Application")

      app_path = Request.ServerVariables("APPL_PHYSICAL_PATH")
      
      'Open FTV file
       ftobj.FTExecuteFormula "File('open';'" & app_path &
"inventory.ftv')"
       
       'Set autosave with no prompting
       ftobj.FTExecuteFormula "File('SetAutoSave';1)"
      
      'Clear all data from the view
      ftobj.FTExecuteFormula "View('discarddata',
'inventory_totals' )"
      
      'Calculate View
      ftobj.FTExecuteFormula "View( 'Calculate',
'inventory_totals' )"
      
      'Draw graph
      ftobj.FTExecuteFormula "Graph( 'Calculate',
'inventory_totals', 'Inventory' )"
      ftobj.FTExecuteFormula "View( 'Paint', 'inventory_totals'
)"
      
      'Write graph to jpeg file
      ftobj.FTExecuteFormula "Graph( 'Export',
'inventory_totals', 'Inventory', '&thisAppPath&inventory.jpg', 'JPEG'
)"
      ftobj.FTExecuteFormula "File('new')"
      
      Set ftobj = Nothing
   End Sub
%>

<h3>Example using ASP to return a graph from F&T OLE Automation
server</h3>
Enter item name, then the amount, click enter to update values in the
FTV and redisplay the graph.

<form method="POST" action="inventory.asp">
<p>
Item name <input type="text" name="item" size="20">
Amount <input type="text" name="amount" size="10">
 <input type="submit" value="Enter">
</p>
</form>

<%
   If Request("cleardata") = 1 Then
      DiscardData
   Else   
      RecalcInventory Request.Form("item"),
Request.Form("amount")
   End If
   
   Response.Write "<img border='0' src='inventory.jpg'>"
%>

<form method="POST" action="inventory.asp?cleardata=1">
<p>
<input type="submit" value="Clear data">
</p>
</form>

</body>
</html>

Attachments

1558720514778000056070_sktwi1f5rjvs16vpp.jpeg get_app
1558720512977000056070_sktwi1f5rjvs16vpo.jpeg get_app
1558720511036000056070_sktwi1f5rjvs16vpn.jpeg get_app
1558720509022000056070_sktwi1f5rjvs16vpm.jpeg get_app
1558720507146000056070_sktwi1f5rjvs16vpl.jpeg get_app
1558720505224000056070_sktwi1f5rjvs16vpk.jpeg get_app
1558720503183000056070_sktwi1f5rjvs16vpj.jpeg get_app
1558720501257000056070_sktwi1f5rjvs16vpi.jpeg get_app
1558720499136000056070_sktwi1f5rjvs16vph.jpeg get_app
1558720497426000056070_sktwi1f5rjvs16vpg.jpeg get_app
1558720495426000056070_sktwi1f5rjvs16vpf.jpeg get_app