Wednesday, October 12, 2011

Need to make a ton of copies of a Trading Partner Really Fast?


Last week I was asked to do something I personally have never done before, create 721 copies of a trading partner with a different EDI and App code and a unique partner id for each for a project needing divisional lookups. Now having suffered through the 30+ partners needed to make Ford happy I had no intentions of copying and pasting 721 DUNs numbers: so I quit the job and am now happily flipping burgers at BK. Just kidding; however, it made me wonder who is actually luckier, oh and by the way "the first 855s will be going out tomorrow morning".

Ok so here is what I did utilizing a little ingenuity and a quick VBScript.

1) Created a template trading partner with Gentran's Trading Partner manager and export the partner to the partners directory. Being sure to use Tag words.



2)Create a text file list of all my divisional lookup values.

012345671
012345672
012345673
012345674

3) Ok Next I created my vbscript. Your lucky I'm sharing the one I created right here.


' Example: cscript GenerateGentranPartners.vbs "C:\GENSRVNT\Partners\GHX - REPVAL.par" C:\PartnerList.txt C:\GENSRVNT\Partners\ ProfileID

' ******************************************************************************
' ******************************************************************************
' ** Create Gentran Partners Script **
' ** Version 0.0.1 **
' ** **
' ** Stephen Case **
' ** http://www.ediassociates.com **
' ** **
' ** Usage: **
' ** cscript.exe GenerateGentranPartners.vbs **
' ** **
' ** - An original working partner export from Gentran **
' ** - A list of values the new Gentran partners will be based on. **
' ** - Output Destination **
' ** - Gentran Partner Profile ID **
' ** **
' ******************************************************************************
' ******************************************************************************

option Explicit

Private strLoadDir, strLoadFile, QueueFolder, strLoadList, strProfileID
Private objFSOi, objFSOo
Private strSubDelim, strTerm, startPnt, i
Dim objSource, saveName
Dim intIndex

Call Main()

Sub Main


If (LoadParams) Then

set objFSOi = CreateObject("Scripting.FileSystemObject")
set objFSOo = CreateObject("Scripting.FileSystemObject")
Call GatherFiles
Else
DisplayUsage
End If
End Sub

Private Sub DisplayUsage

WScript.Echo "Usage: cscript.exe GenerateGentranPartners.vbs "

End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Function LoadParams

dim blnResult
' Pick up our three command line values.
If (WScript.Arguments.Count = 4) then
strLoadFile = WScript.Arguments(0)
strLoadList = WScript.Arguments(1)
QueueFolder = WScript.Arguments(2)
strProfileID = WScript.Arguments(3)
blnResult = true
Else
blnResult = false
End If

LoadParams = blnResult

End Function

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Sub GatherFiles

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strLoadFile) Then
Call SplitFile()
End If

End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
Private Sub SplitFile()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim objFileInT, objFileInL
Dim objFileOut
Dim strLine, tplLine
Dim WrkString, tpString, tpName
Dim oFileName
Dim LineCnt
Dim fso, MyFile

Set fso = CreateObject("Scripting.FileSystemObject")

LineCnt = 0

Set objFileInT = objFSOi.OpenTextFile(strLoadFile)
While (not objFileInT.AtEndOfStream)
tplLine = objFileInT.ReadLine
Wend
' WScript.Echo tplLine
Set objFileInL = objFSOi.OpenTextFile(strLoadList)
While (not objFileInL.AtEndOfStream)
strLine = objFileInL.ReadLine
LineCnt = LineCnt + 1
WrkString = tplLine

WScript.Echo QueueFolder & strProfileID & LineCnt & ".par"
oFileName = QueueFolder & strProfileID & LineCnt & ".par"
tpString = " " & strProfileID & LineCnt & " "
tpName = strProfileID & LineCnt & " - " & strLine
WrkString = Replace(WrkString, "REPNAME", tpName)
WrkString = Replace(WrkString, "REPVAL", strLine)
WrkString = Replace(WrkString, " "&strProfileID&" ", tpString)
Set MyFile = fso.OpenTextFile(oFileName, ForWriting, True)
MyFile.WriteLine WrkString
MyFile.Close

Wend
objFileInL.Close
End Sub

'----------------------------------------------------------------------------------------------------------------------------------------------
'File Exists function made by:
'Paw Jershauge
'http://Support.scf.dk
Public Function FileExists(Filename,Output)
on error resume next
dim fso 'create variables
set fso=Server.CreateObject("Scripting.FileSystemObject") ' creating the File System Object one server, provided by Microsoft)
Output = cbool(fso.FileExists(Filename))
set fso=nothing 'Kill the FSO object from the server after use.
if err.number <> 0 then 'if an error occurred then
ErrNum = err.number 'Save Error number for Get Error Function
ErrDes = err.description 'Save Error description for Get Error Function
err.clear 'Clear the err object, so new errors can be processed
FileExists = false ' return false because of the error that occurred
else
FileExists = true ' return true No errors :o)
end if
End function


4) Here is the command line for useing the script.
cscript C:\pathto\GenerateGentranPartners.vbs

Example: cscript C:\pathto\GenerateGentranPartners.vbs"C:\GENSRVNT\Partners\GHX - REPVAL.par" C:\PartnerList.txt C:\GENSRVNT\Partners\ GHX

5) Once the partner files have been created you can schedule a GDW_Partner_Import through Gentrans Process Controller to import all the partners in one sweep. Just a note to import my 721 partner took close to 45 minutes.

Happy Gentraning...

Saturday, October 1, 2011

Gentran - Need to Send that 997 Now

Recently I was visiting a client whom had a need to send functional acknowledgments instantly upon a transactions receipt. This works fine for any transaction being imported through the Process Controller as you can always put a GDW_Send at the end of the import workflow; but there is no mechanism for automatically sending those pesky 997s or any other system documents that were generated from data passing through the mailboxes and are not part of a Process Control work flow? Now you could setup a send session to run every one or two minutes; however, at times of great traffic those session can start to backup in the queue and really bog down the server. So is an alternative that will only send 997s as they are generated. As a note it has worked well in testing; however, I have not tried it yet on a large volume server, so I do not know what if any issues could come out of it. That said here is how it works.

1. Create a send session of the mailbox that will be sending the data.
2. Create a new Event and set it up as a Notification Type of Event.
3. Setup a new Audit Message under Gentran:Server Configuration, Audit/Notification Tab, under the Audit Messages button.
4. Setup a new Notification under Gentran:Server Configuration, Audit/Notification Tab, under the Notifications button.
5. Here is where everything gets tied together. Position an auditlog command under the Session Rules, Post-session so as the map closes it will initiate the Send Tutorial created in step 1.
6. Compile and Register the map and enjoy…