You might find some nuggets in this…….
The ref to a bat file is just to make permissions easier change directory and the launch of this script is handled by a 3 line lat file which is not always necessary.
‘*************************************************************************************************************************
‘Author: Mike Johnson Sept 2009
‘Optimized for an Epicor Vantage ERP System
‘Purpose to modify the Trading Partner value on an outbound invoice to be the TP related to the
‘ShipTo’ rather than the ‘BillTo’
‘Also to make the PONum and Date/Time part of the file name for archive purposes
‘CAUTION THIS IS A LIVE SCRIPT THAT IS MOVING DATA.
‘*************************************************************************************************************************
‘This script is launched by a 3 line bat file ‘VantageTo810.bat’ that facilitates system run script permissions
’10’*********************************************************************************************************************
Modify_Invoice_Flat_Files ‘Calls a function
‘*************************************************************************************************************************
FUNCTION Modify_Invoice_Flat_Files
Dim objFldr, objFso, objFileIn, objFileOut
Dim strFilePath, strFileIn, strFileOut, strLineIn, strLineOut, strFullPath, strSection, strElement
Dim strFind, strReplaceWith, strTime, strStamp, strPO, strHajoca, strDest, strArchive
Dim aryLine
Dim intIndx
’19
Const conReading = 1
strFilePath = “\\Vantage-Server\Epicor\edi_data\outbound\810”
strDest = “\\epicor\evision\outbound\810\Transfer”
strArchive = “\\Vantage-Server\Epicor\edi_data\outbound\Archive_810”
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set objFldr = objFso.GetFolder(strFilePath)
FOR EACH f in objFldr.files
’27
strFileIn = objFso.GetFileName(f)
IF InStr(strFileIn, “Result”) = 0 THEN
strFullPath = strFilePath & “” & strFileIn
Set objFileIn = objFso.OpenTextFile(strFullPath, conReading)
DO UNTIL objFileIn.AtEndOfStream
strLineIn = objFileIn.ReadAll
aryLine = Split(strLineIn, “~”)
For i = 0 to uBound(aryLine)
IF i = 1171 THEN
’38
strPO = uCase(Trim(cStr(aryLine(i))))
END IF
IF i = 1183 AND uCase(Left(Trim(cStr(aryLine(i))), 6)) = “HAJOCA” THEN
strHajoca = “T”
END IF
IF i = 1235 AND strHajoca = “T” THEN
strFind = uCase(Trim(cStr(aryLine(i))))
IF Left(strFind, 3) <> “HAJ” THEN
’49
MsgBox “Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1236” & VBCRLF _
& “Write down this error message and call IT.”
END IF
END IF
IF i = 1708 AND strHajoca = “T” THEN
strReplaceWith = uCase(Trim(cStr(aryLine(i))))
IF Left(strReplaceWith, 3) <> “HAJ” THEN
’58
MsgBox “Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1708” & VBCRLF _
& “Write down this error message and call IT.”
END IF
END IF
NEXT
LOOP
strTime=Replace(TIME(),”:”,”-“)
strTime=Replace(strTime,” “,””)
strStamp=MONTH(DATE)&”-“&DAY(DATE)&”-“&RIGHT(YEAR(DATE),2)&”_”&strTime
strFileOut = “Result_” & strStamp & “_PO_” & strPO & “.txt”
strDest = strDest & “” & strFileOut
’70
strArchive = strArchive & “” & strFileOut
Set objFileOut = objFso.CreateTextFile(strDest, True)
IF strHajoca = “T” THEN
objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith))
ELSE
objFileOut.Write(strLineIn)
END IF
Set objFileOut = objFso.CreateTextFile(strArchive, True)
IF strHajoca = “T” THEN
’82
objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith))
ELSE
objFileOut.Write(strLineIn)
END IF
objFileIn.close
objFso.DeleteFile strFullPath, force
’90
END IF
NEXT
END FUNCTION
‘**************************************************************************************************************
Set objFldr = nothing
Set objFso = nothing
Set objFileIn = nothing
Set objFileOut = nothing
‘100
strFilePath=””
strFileIn=””
strFileOut=””
strFullPath=””
strLineIn=””
strLineOut=””
strSection=””
strElement=””
strFind=””
strReplaceWith=””
strDest = “”
strArchive=””
aryLine=””
intIndx=””
Discuss This Question: