Integra for Notes Banner
  QuickReports Integra4Notes Integra Family of Products



How to export data from documents stored in a Notes database which is different from the database from where the Integra profile is triggered

You may require Integra to process a document selected in one Notes database, but collect related documents stored in another Notes database. This FAQ explains how this can be achieved.

This is an example scenario. I have a Notes database which stores a list of companies and a second Notes database which stores a list of invoices raised for the companies stored in the first Notes database. The user will select a company document in the first Notes database and the invoices stored in the second Notes database related to the selected company need to be exported to Excel.

The requirement here is that though the user selects a company document, Integra should export the invoice documents stored in a second Notes database. The Callback Script (advanced tab in the Integra profile) code sample below shows how to "tricks" Integra at runtime to work on a different document collection then the user actually selected.

A few points to be noted to make this example work:
  • Though the user selects a single main document (company document), the Excel export profile needs to be set to Export Type = "Report". Mainly because otherwise Integra will not create a correct Excel template format when using the Edit Template button first time.
  • As long we do not use the sorting and grouping feature, Integra is exporting document collections using an intermediete array using its own sorting algorythm. As we replace the document collection, but not the internal array, it is required that we use the sorting and grouping feature in the Integra profile.

Click here if you want to export parent and response documents stored in the same Notes database.
' THIS CODE SAMPLE WORKS ONLY WITH INTEGRA FOR NOTES 4.1 BUILD 32 OR LATER !
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

select case stats.cbstatus
case CB_INITIALISE
case CB_BFOREXPORT
case CB_BFORREADNOTES

' If this event is called for the first time, retrieve the document collection from the second Notes database
' and set the required Integra properties to process the new document collection (i.e. the invoice documents)
if stats.fstcall then
dim tmpdb  as notesdatabase
dim tmpvw  as notesview
dim key_str as string

' Read the value from the current document (company document) which will be used to collect the invoice
' documents from the second database
key_str = stats.expdoc.CompanyName(0)

' Set the Integra profile to export type Report
export.record.structure.TempType = "Report"

' Get a handle to the second database i.e. the one storing invoices - replace newdbname.nsf with
' the database file path
set tmpdb = session.getdatabase(stats.srcdb.server,"newdbname.nsf")

' Get a handle to the view in the second database which will be used to search for the related invoice
' documents
set tmpvw = tmpdb.getview("viewname")

' Retrieve the invoices related to the selected company document and change the document
' collection processed by Integra to the collection of invoices
set stats.doccol = tmpvw.getalldocumentsbykey(companyname)

' Display an error message when no related invoices are found.
if stats.doccol.count = 0 then
export.continue = false
msgbox "No invoices found!"
end if

' Re-assign the database handle used by Integra to the second database i.e. the one containing the invoices
set stats.srcdb = tmpdb

' Re-assign the view handle used by Integra to the view used to collect the invoices
set stats.view = tmpvw

' Re-assign the first document to be exported
set stats.expdoc = stats.doccol.getfirstdocument()

' As we already passed Integra's document validation, we need to do it again
do while not stats.expdoc is nothing
if stats.expdoc.isvalid and not stats.expdoc.isdeleted then
exit do
end if

set stats.expdoc = stats.doccol.getnextdocument(stats.expdoc)
loop

' Re-assign the number of documents to be exported
stats.keynum = stats.doccol.count
end if

case CB_BFORWRITECOM
case CB_AFTERWRITECOM
case CB_BFORCOMACTION
case CB_BFORNOTESACTION
case CB_TERMINATE
end select

.




FAQ# 0222
Bookmark and Share

 
QUICK LINKS
 
 

 

  © Shireburn Software Ltd. 2008 - 2024