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

Aki_Daiguji
Star Contributor
Star Contributor

Hi Scott,

It seems like you have already requested a support issue for the same issue, and we have provided support for the issue. Please let your first line of API support know if you have any questions about this issue ticket.

As far as this issue is concerned, it is by design for System Task to go to focus onto the viewer for executing the task, instead of the folder list. An SCR has been created (SCR#136201) and it is currently not considered to be changed at this time.

Scott_Johnson3
World-Class Innovator
World-Class Innovator

Hi Aki

As note to everyone on this issue, in the 12 unity client ONLY this worked AS EXPECTED. However in the 13 unity hyland BROKE the ability use system tasks on multiple document so if you depend on this functionality in the unity client as I do DO NOT UPGRADE UNTIL IT IS FIXED!!!!!!!!!!  I have another SCR on the unity BUG and it is #172306.

Scott

Marcus_Christi6
Star Contributor
Star Contributor

Scott,

Curious why you're trying to use VB Automation API in Unity System Task instead of the Unity Automation API?

Unity Automation contains as part of it the ability to run things as a batch which in my experience works in all parts of Unity.  That's in 12 and 13, so I'm just wondering if that's your issue.

Scott_Johnson3
World-Class Innovator
World-Class Innovator

Hi Marcus

I generally do use unity but found a good script written in vb that was close to what I needed. So I took the lazy way out and left it in VB.  The multi-select issue very much exists with unity automation  API.  Just try writing "Hello World" the the diag console using the Unity automation API under a system task from a folder.  You will see that only one line is written to the diag console no matter how many documents you select.  You do the same from a document retrieval hit list and you will get one "hello world" for every document selected.

Scott