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...

1 comment:

  1. Hi,

    we are in the similar situation, only we are to upload a lot of new partners, not just the DUNS with same partner id.

    Is there any way that could be done with help of a script or some additional facility? I'm not much into VBScripts, so can't really write one of my own. Can yours be modified to achieve this feat?

    Any help you can extend is deeply appreciated.

    Regards,
    Shraddha
    imshraddha@gmail.com

    ReplyDelete