Hey guys,
Im trying to write a script, which automatically renames the file based on the input of a textfile and the OCZ Zone.
So the idea is as follows:
The OCR Zone gets parsed for the ABN by the script and compares it to a textfile. If part of the ocr zone matches a line in the textfile, it will create a new variable which contains the associated VendorID for the ABN. This variable can now be used to rename the file accordingly.
e.g.
The textfile could look like this
51 824 753 556=K67890
41 824 753 556=K54321
...
41 824 753 556 is found, so the value of the new variable (e.g. filename) will be set as K54321 and can now be used to rename the file.
The OCR Zone is set quite large as we get numerous invoices with different layouts so the position of the ABN varies.
I tried to write a script, but as I've never used VBScript before it doesnt quite work well. Used part of https://forum.scanshare.com/thread/script-extract-data-from-invoice/ as you can see.
I appreciate your help.
ocrText = Metadata.Values("OCR_ZONE01")
VendorNumber = Metadata.Values("VendorID")
Dim Target, Target2
Target = ".*(ABN: |ABN:|Tax Number: |A.B.N. |A.B.N.|ABN |ABN|abn:|abn: |A.B.N |)\$*(([0-9]{2} [0-9]{3} [0-9]{3} [0-9]{3})|([0-9]{11}))"
Dim arrLines
arrLines = Split(ocrText, "\r\n")
call Metadata.SetValues("MY_SUPPLIER_ABN", "## NOT FOUND ##")
Dim matchedValue
For Each strline in arrLines
match = GetFirstMatch(target, strline)
If match <> "" Then
call Metadata.SetValues("MY_SUPPLIER_ABN", match)
End If
Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fspenTextFile(C:\ProgramData\Scanshare\Test.txt)
Do Until f.AtEndOfStream
LineTxt = WScript.Echo f.ReadLine
search="="
Business=left (LineTxt, instr(LineTxt, search)-1)
Vendor=right (LineTxt, len(LineTxt)-instrrev (LineTxt, search))
if Business = MY_SUPPLIER_ABN then
Vendor = VendorNumber
end if
f.Close
Function GetFirstMatch(PatternToMatch, StringToSearch)
Dim objRE , CurrentMatch, objMatch
Set objRE = New RegExp
objRE.Pattern = PatternToMatch
objRE.IgnoreCase = True
objRE.Global = False
Set objMatch = objRE.Execute(StringToSearch)
GetFirstMatch = ""
If objMatch.Count = 1 Then
GetFirstMatch = objMatch.Item(0).Submatches(1)
End If
Set objRE = Nothing
End Function