WOOHOO!! Finished the code...

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
..for my first coding project here at work. :D

Now onto the validation and implementation... :|

I wish my job entailed more of this. There's just nothing like the feeling you get when you create something like this that actually works the way you want. :)

The VBScript code, in all it's splendor....or lack thereof: ;)

Option Explicit

Sub Main()
Dim iResult
Dim i
Dim oFS 'File Object
Dim oFile 'TextStreamObject
Dim strInput 'File Input
Dim strProductGroup 'Product Group that the item belongs too, Raw Material, Bulk, Packaged
Dim sArray 'Array of items split from strInput
Dim strProductID
Dim strLotNumber

sapphire.enableaps
sapphire.enabledbs

Set oFS = CreateObject("Scripting.FileSystemObject")

If NOT oFS.FileExists("c:\Test.txt") Then
Exit Sub
Else
Set oFile = oFS.OpenTextFile("c:\Test.txt",1,0)
End If

strInput = oFile.ReadAll
oFile.Close

sArray = Split(strInput,",")
For i = LBound(sArray) to UBound(sArray)
If i <> 0 Then '0 based array work around
iResult = i Mod 2
If iResult = 0 Then
strProductID = sArray(i)
Call ProductType(strProductGroup,strProductID)
Else
strLotNumber = sArray(i)
Call CreateSubmission(strProductGroup, strProductID, strLotNumber)
End If
Else
strProductID = sArray(i)
Call ProductType(strProductGroup,strProductID)
End If
Next

End Sub

'***************SUB PRODUCTTYPE***************

Sub ProductType(strProductGroup, ByVal strProductID)
Dim sqlSaphProd
Dim recSaphProd
Dim intSaphProd

sqlSaphProd = "select productgroup from u_product where u_productid = '"+strProductID+"'"
recSaphProd = sapphire.dbs.OpenDataSet(sqlSaphProd)
If recSaphProd <> -1 Then
intSaphProd = sapphire.dbs.GetRows(recSaphProd)
If intSaphProd Then
strProductGroup = sapphire.dbs.GetValue(recSaphProd,1,1)
'strProductGroup = LCase(strProductGroup)
End If
End If

sapphire.dbs.Close recSaphProd

End Sub

'***************SUB CREATESUBMISSION***************

Sub CreateSubmission(ByVal strProductGroup, ByVal strProductID, ByVal strLotNumber)

sapphire.aps.setproperty "sdcid","Submission"
sapphire.aps.setproperty "templateid","Manual"
sapphire.aps.setproperty "u_lab","QC - Quality Control"
sapphire.aps.setproperty "u_submitted_by","Manufacturing"
sapphire.aps.setproperty "u_submission_status","Registered"
sapphire.aps.setproperty "u_product",strProductID
sapphire.aps.setproperty "u_lot_number",strLotNumber
sapphire.aps.setproperty "u_submission_type",strProductGroup & " Release"

sapphire.aps.ProcessAction "AddSDI"

End Sub