RE: Internet Fields Population Integration Manager
Due to problems on my dev box I haven't been able to test the following as a whole although the VBA is based off another one I did recently and the SQL has been used individually.
The following goes against the Before Integration script hook:
' BEFORE INTEGRATION
Dim oCon
Dim sINTERID
Set oCon = CreateObject("ADODB.Connection")
oCon.ConnectionString = "database=" & GPConnection.GPConnIntercompanyID
GPConnection.Open(oCon)
SetVariable "gblConn", oCon
The following goes against the After Document script hook:
' AFTER DOCUMENT
Set oCmd = CreateObject("ADODB.Command")
With oCmd
.ActiveConnection = GetVariable("gblConn")
.CommandText = "SELECT TOP 1 COUNT(EmailToAddress) AS Count FROM SY01200 WHERE Master_ID = '" & SourceFields("VendorEmails.VENDORID") & "' AND ADRSCODE = '" & SourceFields("VendorEmails.ADRSCODE") & "'"
Set rsQuery = .Execute
If Not (rsQuery.EOF and rsQuery.BOF) Then
If rsQuery("Count") > 0 Then
.CommandText = "UPDATE " & _
"SY01200 " & _
"SET " & _
"EmailToAddress = '" & SourceFields("VendorEmails.EmailToAddress") & "', EmailCcAddress = '" & SourceFields("VendorEmails.EmailCcAddress") & "', EmailBccAddress = '" & SourceFields("VendorEmails.EmailBccAddress") & "' " & _
"WHERE " & _
"VENDORID = '" & SourceFields("VendorEmails.VENDORID") & "' AND ADRSCODE = '" & SourceFields("VendorEmails.ADRSCODE") & "'"
Set rsUpdate = .Execute
Else
.CommandText = "INSERT SY01200 " & _
"(Master_Type,Master_ID,ADRSCODE,INETINFO,EmailToAddress,EmailCcAddress,EmailBccAddress) " & _
"VALUES " & _
"('VEN','" & SourceFields("VendorEmails.VENDORID") & "','" & SourceFields("VendorEmails.ADRSCODE") & "','','" & SourceFields("VendorEmails.EmailToAddress") & "','" & SourceFields("VendorEmails.EmailCcAddress") & "','" & SourceFields("VendorEmails.EmailBccAddress") & "')"
Set rsInsert = .Execute
End If
End If
rsQuery.Close
Set oCmd = Nothing
End With
The above VBA assumes your integration record source is called VendorEmails and you have the following columns:
- VENDORID
- ADRSCODE
- INETINFO
- EmailToAddress
- EmailCcAddress
- EmailBccAddress
The script checks if the email information exists and if it does then it does an update, otherwise it does an insert.