286 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
If Instr(cust_id, "[") > 0 And Instr(cust_id, "]") = Len(cust_id) Then
'extract ID from input patameter
cust_id = Strleft(Strrightback(cust_id,"["), "]")
End If
Set view = db.getView("Customers")
'get the document
Set entry = view.GetDocumentByKey(cust_id, True)
If Not entry Is Nothing Then
'read the fields
cInfo.cust_id= entry.getItemValue("cust_id")(0)
cInfo.cust_name= entry.getItemValue("cust_name")(0)
cInfo.cust_amgr= entry.getItemValue("cust_amgr")(0)
cInfo.cust_contact_name= entry.getItemValue("cust_contact_name")(0)
cInfo.cust_contact_position= entry.getItemValue("cust_contact_position")(0)
cInfo.cust_contact_phone= entry.getItemValue("cust_contact_phone")(0)
cInfo.cust_contact_email= entry.getItemValue("cust_contact_email")(0)
cInfo.cust_crm_no= entry.getItemValue("cust_crm_no")(0)
Else
Messagebox "entry not found: " & cust_id
End If
Set getCustInfo = cInfo
Exit Function
errorhandler:
Messagebox "Error " & Err() & " in " & Lsi_info(2) & " line " & Erl() & ": " &
Error$
Resume Next
End Function
End Class
Save the service — it is ready to run.
The same procedure should be processed for the other Web services (EmployeeInfo and
ProductInfo).
9.5.2 Template Database: components to create a new form from template
The Template Database has the role of the application database. It will contain several
correlated design elements, which work together when creating new forms or opening
existing forms in the browser.
For form creation, we will have to create the following components:
򐂰 A form to store templates
򐂰 A form to render the HTML page shown to the browser when creating a new request
򐂰 An initiation agent that will fill the rendering form
򐂰 A View listing all available forms along with suitable links to compose a new XFDL form
from the template
򐂰 At least one stored template with prepopulation settings applied to test the created design
elements.
Tip: The EmployeeInfo Web service is created but not used in the redpaper demo XFDL
form. You might not want to create it.
Chapter 9. Domino integration 287
򐂰 A parameter form and view storing necessary application parameters (order count, server
URL,etc.)
The database will receive submitted forms as well — so we need an additional form to store
submitted forms and at least one lookup view to find the related document on subsequent
updates to the submitted XFDL documents, for example, those going through the approval
workflow. We will create all these components in the next sections.
Parameter form and view
Here, we will create one simple form to store some application parameters. We will use these
documents to store the DNS name of the server using it to create http links and we will store
here the order number counter that increments on each new order creation. Give it an
additional author field (Figure 9-9).
Figure 9-9 Parameter Form in Template Database
For lookup and maintenance, create one view sorted by field PAR_KEY like this (make sure
that the fourth column presents the @DocumentUniqueID (Figure 9-10).
Figure 9-10 Parameter lookup view
Template form
The template form will basically store the form templates as file attachments in a rich text
field. Create a form named FormTemplate like this (Figure 9-11).
Figure 9-11 Basic fields for template storage
288 IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application
The name field should contain a short name for the template. This will be the link text that is
presented to the end user when creating a new form from the template.
This form should not store only the form XFDL template, but contain also some additional
functionality:
򐂰 It gets a set of fields used to define any prepopulation applied to the template when
creating a new form. This makes it possible to run a generic prepopulation module, and
prepopulate a different data set on form initiation.
򐂰 It needs to provide a converted version of the original XFDL template that can be easily
accessed in the prepopulation moment.
To convert the attachment, open the PostSave event of the form and insert the following code
(Example 9-5).
Example 9-5 Attachment converting in PostSave event
Sub Postsave(Source As Notesuidocument)
'detach the attachment to temp directory and store it back to bodyInline field as mime
type
Dim doc As NotesDocument
Set doc = source.Document
Dim session As New NotesSession
Dim rtitem As NotesRichTextItem
'get the body field
Set body = doc.GetFirstItem("Body")
Call body.update
'get temp dir
tmpdir = Environ("temp")
If tmpdir = "" Then tmpdir = Environ("tmp")
If tmpdir = "" Then tmpdir = "c:\temp"
Dim sep As String
sep = "\"
If Instr(tmpdir, "/") > 0 Then sep = "/"
Dim fileId As Variant
'get attachment (should be only one!!)
Forall att In body.EmbeddedObjects
If att.Type = EMBED_ATTACHMENT Then
filepath = tmpDir & sep & att.Source
Print "filepath: " & filepath
Call att.ExtractFile(filepath)
found = True
End If
End Forall
'Read the detached file into inputstream and append to Body richtext field on rendering
form
Dim stream As NotesStream
Set stream = session.CreateStream
If Not stream.Open(filepath, "ISO-8859-1") Then
Print "Open failed"
Exit Sub
Else
Print "Opened file " + filepath
End If
If stream.Bytes = 0 Then

Get IBM Workplace Forms: Guide to Building and Integrating a Sample Workplace Forms Application now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.