Integra for Notes Banner
  QuickReports Integra4Notes Integra Family of Products



How to export data from response documents for multiple parent documents - Generic Code Sample

Data in Notes documents is frequently held in response documents but some additional data related to the response document may also be required to be exported from the response document's parent document. This FAQ explains how this is achieved using Integra for Notes.

The sample code provided below is generic and can be applied to any Integra profile by making a few amendments to the customisable parts at the top of the code.

Firstly, create a Word profile linked to the Notes form which is the response documents' form. Select the fields that you want to export from the main and/or response documents. You can use computed fields (type formula) to compute the value of the field depending upon the document being exported.

This is the scenario for exporting response documents (POItem) for multiple parent documents (PurchaseOrder). I have a Notes database with purchase orders. Each purchase order has a heading document with e.g. details of the supplier and n numbers of line items (stored as Notes response documents). The user selects one or more purchase order header documents and runs Integra to create a well formatted purchase order in Word.

The requirement here is that though the user selects the parent document(s), Integra should export the response documents. The Callback Script (advanced tab in the Integra profile) code sample below shows how to export the response documents for each parent document processed.

The customised settings in example code is based on the following fields in the Selected Field List of the Integra profile:

Supplier Name (Text) - this field is stored on the parent document (PurchaseOrder)
Address (Formula e.g. Address+" "+Town+" "+Country) - this field is stored on the parent document (PurchaseOrder)
PONumber (Text) - this field is stored on the parent document (PurchaseOrder)
POItemName (Text) - this field is stored on the response document (POItem)
POItemQty (Numeric) - this field is stored on the response document (POItem)
POItemCost (Numeric) - this field is stored on the response document (POItem)
POItemTotalCost (Numeric) - this field is stored on the response document (POItem)
POTotal - (Numeric) - this field is stored on the parent document (PurchaseOrder)

Note that you may select fields from multiple response documents

'**********************************************
' DEFINE THE CUSTOMISED PROFILE SETTINGS BELOW

' Enter the name of the parent form 
Const ParentForm = "PurchaseOrder"

' Enter the response forms containing the fields from which the fields in the field list are to be populated
Const RespForm = "POItem,POItem,POItem,POItem,POItem"

' Enter the position of the field in the field list matching the above response forms
Const FieldPos = "2,3,4,5,6"

' Set to True to export the parent document if no responses are found
Const ExportParentIfNoResponses  = True

'*********************************************


Const CB_INITIALISE = 3
Const CB_BFOREXPORT = 10
Const CB_BFORREADNOTES = 6
Const CB_BFORWRITECOM = 1
Const CB_AFTERWRITECOM = 9
Const CB_BFORCOMACTION = 5
Const CB_BFORNOTESACTION = 2
Const CB_TERMINATE = 4

dim tmpcol as notesdocumentcollection
dim tmpdoc as notesdocument
dim frms as variant
dim fldpos as variant
dim fldnm as string
dim fldval  as variant
dim fldfm  as string
dim fldres as string
dim i as integer


select case stats.cbstatus
case CB_INITIALISE
case CB_BFOREXPORT
case CB_BFORREADNOTES

' Do not process selected documents which are not parent documents
if not lcase(stats.expdoc.Form(0)) = lcase(ParentForm) then
export.continue = false
end if

case CB_BFORWRITECOM

' Validate the response form and field position constants specified above
frms = Split(RespForm,",")
fldpos = Split(FieldPos,",")

if not ubound(frms) = ubound(fldpos) then
msgbox "Please re-check the response forms and the field positions entered"
export.continue = false
end if

' Make sure that the field positions are blank (this is done just in case the response document
' fields are not set to Formula in the selected field list)
if export.continue then
for i = 0 to ubound(frms)
export.record.fvalue(fldpos(i)) = ""
next
end if

if ExportParentIfNoResponses then
' Export the parent document even if no responses are found
call export.WriteNext(stats)
elseif stats.expdoc.responses.count = 0 then   
' Do not export the parent document if no responses are found
export.continue = false
else
' Export the parent document if responses are found
call export.WriteNext(stats)
end if

if export.continue then
' Store the responses to the current parent document in a temporary document collection
set tmpcol = stats.expdoc.responses

if tmpcol.count = 0 then
' Exit if parent documents are not to be exported if they have no responses
' (as per ExportParentIfNoResponses setting)
if not ExportParentIfNoResponses then
export.continue = false
end if
else
set tmpdoc = tmpcol.getfirstdocument

' Loop through response documents
do while not tmpdoc is nothing

' Loop through response forms
for i = 0 to ubound(frms)
if trim(lcase(tmpdoc.Form(0))) = trim(lcase(frms(i))) then
fldnm =  export.record.structure.fname(fldpos(i))
fldfm   = export.record.structure.FMacr(fldpos(i))

' If the field contains a formula, the formula is evaluated, otherwise the field value is taken
if Trim(fldfm) = "None" or Trim(fldfm) = "" then
fldres = tmpdoc.GetItemValue(fldnm)(0)
else
fldres = EvaluateFormula(fldfm,tmpdoc)
end if

' The response document values for each field are concatenated
if export.record.fvalue(fldpos(i)) = "" then
export.record.fvalue(fldpos(i)) = fldres
else
export.record.fvalue(fldpos(i)) = export.record.fvalue(fldpos(i)) & Chr(10) & fldres
end if
end if
next
            
set tmpdoc = tmpcol.getnextdocument(tmpdoc)
loop
end if   

for i = 0 to ubound(frms)
if export.record.fvalue(fldpos(i)) = "" then
export.record.fvalue(fldpos(i)) = "No " & frms(i) & " found"
end if
next

Call export.WriteNextSameDoc(stats)
end if

case CB_AFTERWRITECOM
case CB_BFORCOMACTION
case CB_BFORNOTESACTION
case CB_TERMINATE
end select


.




FAQ# 0229
Bookmark and Share

 
QUICK LINKS
 
 

 

  © Shireburn Software Ltd. 2008 - 2024