cancel
Showing results for 
Search instead for 
Did you mean: 

VB script works different between Doc Retrieval Hit List & Folder Doc List

Scott_Johnson3
World-Class Innovator
World-Class Innovator

I am seeing a difference between in behavior Doc Retrieval Hit List & Folder Doc List.  I wrote a script to get summery info from a doc selection list such as size, page count, and doc count.  In a regular hit list it works fine run directly or off of a system task button.  In a folder doc list runing directly works but run as a system task the accumulators (property bag values) only have the first doc info.  Anyone with thoughts?  Here is the code:

' Used to force variable declaration before usage
Option Explicit

' Declaration for constant used in the script
Const strPropertyBagValue  = "Total File Size"
Const strPropertyBagcnt    = "Page Count"
Const strPropertyBagDocCnt = "Doc Count"


' Preferred method to write VB scripts with OnBase
Sub Main35()
 ' Root level OnBase Automation object
 Dim objApplication
 Set objApplication = CreateObject("OnBase.Application")

 ' Currently active document returned by the root automation object
 ' The script will only have one CurrentDocument during each execution  
 Dim objCurrentDocument
 Set objCurrentDocument = objApplication.CurrentDocument

 ' Keyword collection for the current document 
 Dim objDocumentKeywords
 Set objDocumentKeywords = objCurrentDocument.Keywords
 
 ' Page collection for the current document
 Dim objDocumentPages
 Set objDocumentPages = objCurrentDocument.Pages

 ' PropertyBag object used to carry over data across script executions
 Dim objPropertyBag
 Set objPropertyBag = objApplication.PropertyBag

 ' PropertyBag object used to carry over data across script executions
 Dim DocCount
 DocCount = 1

 ' BatchDocumentsRemaining will be 1 less than the total selected since it is zero based.
 ' When it is 0 it will be on the last document. Used to tell when the script has executed
 ' on all documents that were selected. 
 Dim lngDocumentsRemaining
 lngDocumentsRemaining = objApplication.BatchDocumentsRemaining
 
 Dim lngIndex
 lngIndex = 0
 
 Dim dblFileSize
 Dim PCount
 dblFileSize = 0
 
 ' Loop through the document page collection getting the length in bytes
 ' of each page 
 Do While (lngIndex < objDocumentPages.Count)
  PCount = objDocumentPages.Item(lngIndex).Length
   dblFileSize = dblFileSize + PCount
  lngIndex = lngIndex + 1
 Loop


 ' Force the variant's subtype to a double precision number 
 dblFileSize = CDbl(dblFileSize)

 ' Check to see if a value exists in the property bag.
 ' If not then set a propety in the property bag with the value
 ' of the number we just obtained
 If (Not objPropertyBag.PropertyExists(strPropertyBagValue)) Then
      Call objPropertyBag.SetProperty(strPropertyBagValue, dblFileSize)
 Else
  ' If the property already exists it means weve already run the script
  ' so get the vlaue from the property bag and force the type to
  ' a double to be safe. Then add it to what we've obtained from the current script's
  ' execution
  Dim dblRunningTotal
  dblRunningTotal = CDbl(objPropertyBag.GetProperty(strPropertyBagValue))
  dblRunningTotal = dblRunningTotal + dblFileSize
  ' Store the new property back
  Call objPropertyBag.SetProperty(strPropertyBagValue, dblRunningTotal)
 End If

 If (Not objPropertyBag.PropertyExists(strPropertyBagCnt)) Then
      Call objPropertyBag.SetProperty(strPropertyBagCnt, objDocumentPages.Count)
 Else
  ' If the property already exists it means weve already run the script
  ' so get the vlaue from the property bag and force the type to
  ' a double to be safe. Then add it to what we've obtained from the current script's
  ' execution
  Dim dblRunningTotalCnt
  dblRunningTotalCnt = CDbl(objPropertyBag.GetProperty(strPropertyBagCnt))
  dblRunningTotalCnt = dblRunningTotalCnt + objDocumentPages.Count
  ' Store the new property back
  Call objPropertyBag.SetProperty(strPropertyBagCnt, dblRunningTotalCnt)
 End If

 If (Not objPropertyBag.PropertyExists(strPropertyBagDocCnt)) Then
      Call objPropertyBag.SetProperty(strPropertyBagDocCnt, DocCount)
 Else
  ' If the property already exists it means weve already run the script
  ' so get the vlaue from the property bag and force the type to
  ' a double to be safe. Then add it to what we've obtained from the current script's
  ' execution
  Dim dblRunningTotalDocCnt
  dblRunningTotalDocCnt = CDbl(objPropertyBag.GetProperty(strPropertyBagDocCnt))
  dblRunningTotalDocCnt = dblRunningTotalDocCnt + 1
  ' Store the new property back
  Call objPropertyBag.SetProperty(strPropertyBagDocCnt, dblRunningTotalDocCnt)
 End If

 
 ' When you've worked on all the documents present the results
 If (0 = lngDocumentsRemaining) Then
  ' Display the final file size and format the number to only 2 decimal places. Divide by 1000 to
  ' represent the value in Kilobytes
  Call MsgBox("Total File Size = " & FormatNumber((objPropertyBag.GetProperty(strPropertyBagValue)/1000), 2) & _
       " KBytes" & chr(13) & "Total Page Count = " & FormatNumber((objPropertyBag.GetProperty(strPropertyBagCnt)), 2) & _
       " Pages"  & chr(13) & "Total Doc Count = " & FormatNumber((objPropertyBag.GetProperty(strPropertyBagDocCnt)), 2) & _
       " Documents", vbOKOnly, "File Size")
  ' Clear the property bag of any properties so that the next the
  ' time the script is run it won't have any old properties with
  ' out of date or erroneous property values
  objPropertyBag.Clear
 End If
End Sub ' End Main35()

'Core Services Entry Point
Function Main(oOBSession, objCurrentDocument)
 'NOT IMPLEMENTED!!!

End Function 'Main(oOBSession, oOBCurrentDocument)

7 REPLIES 7

Marcus_Christi6
Star Contributor
Star Contributor

Not sure if it helps.  But using IClientScript, I execute against 5 documents an export task that I created.  It creates 5 PDFs, as expected.


If I read you correctly, you're trying to do something like sum total a bunch of invoices and get a single dollar amount?  It does contain an OnEndBatch where you could in theory do the math that was calculated from OnClientScriptExecute which would just return the single value.  Unless again, I'm misreading what you're trying to do, in which case disregard.

Scott_Johnson3
World-Class Innovator
World-Class Innovator

Hi Eric

Thanks for the reply.  Are you on 13 and did you excute the iclient script on the on contents of a folder?

Thanks

Scott

Marcus_Christi6
Star Contributor
Star Contributor

Name's Marcus 🙂

I am using SP1 of OnBase 13.  Inside a folder I selected all documents and ran the script.  It performed the same way.

What did not work - and I assume this might be what you're referring to - is trying to highlight the folder itself and run the Script Task.  That doesn't work because of the UI, not an API issue.  What's happening there is that Unity is highlighting one document, and the script is executing the one time. 

If that's what you're trying to do then it makes sense why it wouldn't work.  Highlighting the documents inside the folder and doing the Script Task should work perfectly.  At least it did in mine.  13.0.1.98 Core, for what it's worth.

In IClientScript do make sure that the looping and collections are in OnClientScriptExecute, not in OnBeginBatch.