Andrew Angell
asked on
I've got a pretty complicated loop that seems to be looping for all but one small peice...??? Involves XML and lots of updates/inserts. 500 pts!!
I've got a script that grabs data from the eBay API via XML response and parses out the data within a loop. Also within this loop I've added lots of inserts and updates to the database. The idea behind the script is that it's pulling all of the orders from eBay and inserting them into this database system. I'll put it in my own words and then I'm going to supply the entire script because I can't think of another way to explain or show what's going on to get help.
Basically, the script generates an XML request and sends it off to eBay and parses the response within a loop. There are lots of other things that happen within the loop. First, all of the auction records get updated with their status information, high bidder, price, etc. After that, an invoice needs to be inserted for the order into the database. The first step here is to check the customers table to see if the phone number (what's being used as customerID) already exists. If it does, update the info with the data received. If it does not exist, create a new customer record with the data received. Moving on from there, the invoice information is inserted into the database (using 3rd party WebAssist extensions in Dreamweaver) which populates the basic information and also stores the new invoice number into a session variable which is used to populate the related field in the InvoiceItems table.
Everything is working great except that all of the items end up on one single Invoice in the system. At first I had the assumption that the Session wasn't getting updated, therefore all of the items ended up on the same invoice. However, only 1 single invoice is getting created. There should be a new invoice being created for each time through the loop and that doesn't seem to be happening.
Everything else works great. Each auction record gets updated fine. The customer information gets inserted/updated accordingly. I can't figure out why the Insert isn't looping...???
Any information would be greatly appreciated. Here is the script. Go easy on me with the sloppiness of it...I'm merely intermediate.
__________________________ __________ __________ _______
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../WA_eCart/WA_eC art_Defini tion_VB.as p" -->
<!--#include file="../../WA_eCart/WA_eC art_Databa se_VB.asp" -->
<!--#include file="../../WA_eCart/deals DirectCart _VB.asp" -->
<!--#include file="../../Connections/co nnInvoices .asp" -->
<!--#include file="../../Connections/co nnAuctions .asp" -->
<!--#include file="../../Connections/co nnCustomer s.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<%
sandboxTest = 1
If sandboxTest = 1 Then
sURL = "https://api.sandbox.ebay.com/ws/api.dll"
DevID = "DEVID"
AppID = "APPID"
Cert = "CERT"
AuthToken = "TOKEN"
Else
sURL = "https://api.ebay.com/ws/api.dll"
DevID = "DEVID"
AppID = "APPID"
Cert = "CERT"
AuthToken = "TOKEN
End If
'Create eBay GetItem call
'Set buffer and expiration values
Response.Buffer = true
Response.Expires = -1500
'Send POST via MS WinHTTP Services, version 5.1
Set oWinHttp = Server.CreateObject("WinHt tp.WinHttp Request.5. 1")
'Code to grab address and phone number info
'function used to add the 0 to the front of the days in the date
Function longNow(item)
If len(item) = 1 then
longNow = "0" & item
Else
longNow = item
End if
End function
'Set the From and To times so that the script will get transactions for the past 24 hours
ModTimeFrom = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) - 1 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
ModTimeTo = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
'Create GetSellerTransactions Call
GetSellerTransactionsReque st = "<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<GetSellerTransactionsReq uest xmlns=""urn:ebay:apis:eBLB aseCompone nts"">" &_
"<RequesterCredentials>" &_
"<eBayAuthToken>"&AuthToke n&"</eBayA uthToken>" &_
"</RequesterCredentials>" &_
"<DetailLevel>ReturnAll</D etailLevel >" &_
"<IncludeFinalValueFee>1</ IncludeFin alValueFee >" &_
"<ModTimeFrom>"&ModTimeFro m&"</ModTi meFrom>" &_
"<ModTimeTo>"&ModTimeTo&"< /ModTimeTo >" &_
"</GetSellerTransactionsRe quest>"
'Open POST
oWinHttp.Open "POST", sURL, False
'Set necessary headers
oWinHttp.SetRequestHeader "Content-Type","text/xml"
oWinHttp.SetRequestHeader "X-EBAY-API-COMPATIBILITY- LEVEL", "465"
oWinHttp.SetRequestHeader "X-EBAY-API-SESSION-CERTIF ICATE", DevID & ";" & AppID &";" & Cert
oWinHttp.SetRequestHeader "X-EBAY-API-DEV-NAME", DevID
oWinHttp.SetRequestHeader "X-EBAY-API-APP-NAME", AppID
oWinHttp.SetRequestHeader "X-EBAY-API-CERT-NAME", Cert
oWinHttp.SetRequestHeader "X-EBAY-API-CALL-NAME", "GetSellerTransactions"
oWinHttp.SetRequestHeader "X-EBAY-API-SITEID", "0"
oWinHttp.SetRequestHeader "X-EBAY-API-DETAIL-LEVEL", "0"
'Set time out to 60 seconds
oWinHttp.SetTimeouts 60000, 60000, 60000, 60000
'Send XML request to eBay and store response in AddItemResponse
oWinHttp.Send GetSellerTransactionsReque st
GetSellerTransactionsRespo nse = oWinHttp.ResponseText
'Write contents of the response to a file on the server
set fs=Server.CreateObject("Sc ripting.Fi leSystemOb ject")
GetSellerTransactionsRespo nseXML = (server.MapPath("eBayRespo nses/GetSe llerTransa ctionsResp onse.xml") )
set tfile=fs.CreateTextFile(Ge tSellerTra nsactionsR esponseXML )
tfile.WriteLine(GetSellerT ransaction sResponse)
tfile.close
set tfile=nothing
set fs=nothing
'open the XML document
Set xmlDoc = Server.CreateObject("Micro soft.XMLDO M")
xmlDoc.Async = false
xmlDoc.Load(GetSellerTrans actionsRes ponseXML)
'Get the value of Ack - either Success or Failure. store it in AckStatus
Set GetSellerTransactionsRespo nseNode = xmlDoc.selectNodes("/GetSe llerTransa ctionsResp onse")
For Each node In GetSellerTransactionsRespo nseNode
AckStatus = node.selectSingleNode("Ack ").text
Next
Set GetSellerTransactionsRespo nseNode = Nothing
'Check if the call was successful. If failed, create a file
'and print the reason inside it. Store the file in failed folder
If AckStatus = "Failure" Then
Set fs = Server.CreateObject("Scrip ting.FileS ystemObjec t")
filename = Server.MapPath("eBayRespon ses\failed \GetSeller Transactio nsResponse _"&eBayIte mID&".asp" )
Set tfile = fs.CreateTextFile(filename )
Set Failed = xmlDoc.selectNodes("/GetSe llerTransa ctionsResp onse/Error s")
For Each errorNode in Failed
tfile.WriteLine errorNode.selectSingleNode ("ShortMes sage").tex t & "<br>" & errorNode.selectSingleNode ("LongMess age").text & "<p>"
response.Write(errorNode.s electSingl eNode("Sho rtMessage" ).text &"<br>"& errorNode.selectSingleNode ("LongMess age").text )
Next
Set Failed = Nothing
Set xmlDoc = Nothing
tfile.close
Set tfile = Nothing
Set fs = Nothing
response.end
Else
'Create a function to give the variables a value of "" if the node does not exist
'in the XML response
Function TryNode(Node, Loc)
On Error Resume Next
TryNode = ""
TryNode = Node.selectSingleNode(Loc) .Text
End Function
'Create function to generate random number in the case that a phone number isn't returned in the Shipping information
Function getRandomNumber(Length)
Dim Digit
Randomize
Do While Length > 0
Length = Length - 1
Digit = Rnd * 9.9
Digit = mid(Digit, 1, instr(Digit, ".") - 1)
getRandomNumber = getRandomNumber & Digit
Loop
End Function
'Grab the transactions data from the response and update the auction records
'for all transactions returned in the response XML
Set TransactionInfo = xmlDoc.selectNodes("/GetSe llerTransa ctionsResp onse/Trans actionArra y/Transact ion")
For Each node In TransactionInfo
AmountPaid = tryNode(node, "AmountPaid")
BuyerEmail = tryNode(node, "Buyer/Email")
TransactionPrice = tryNode(node, "TransactionPrice")
BuyerFeedbackScore = tryNode(node, "Buyer/FeedbackScore")
BuyerStatus = tryNode(node, "Buyer/Status")
BuyerEbayID = tryNode(node, "Buyer/UserID")
BuyerName = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Nam e")
BuyerStreet1 = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Str eet1")
BuyerStreet2 = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Str eet2")
BuyerCityName = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Cit yName")
BuyerStateOrProvince = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Sta teOrProvin ce")
BuyerPostalCode = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Pos talCode")
BuyerCountry = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Cou ntryName")
BuyerPhoneNumber = tryNode(node, "Buyer/BuyerInfo/ShippingA ddress/Pho ne")
If BuyerPhoneNumber <> "" Then
BuyerPhoneNumber = Replace(BuyerPhoneNumber," )","-")
BuyerPhoneNumber = Replace(BuyerPhoneNumber," (","")
BuyerPhoneNumber = Replace(BuyerPhoneNumber," ","")
Else
'Generate Random Number to use so you can insert the order
BuyerPhoneNumber = getRandomNumber(10)
End If
eBayItemID = tryNode(node, "Item/ItemID")
ListingStatus = tryNode(node, "Item/SellingStatus/Listin gStatus")
AuctionEndTime = tryNode(node, "Item/ListingDetails/EndTi me")
AuctionEndTime = (Left(AuctionEndTime,10))
FinalValueFee = tryNode(node, "FinalValueFee")
ShippingServiceCost = tryNode(node, "ShippingServiceSelected/S hippingSer viceCost")
QuantitySold = tryNode(node, "Item/SellingStatus/Quanti tySold")
'Update the auction record in Filemaker with the details returned above
SQL = "UPDATE Auctions Set WinningBidderEmailAddress = '"&BuyerEmail&"', "&_
"WinningBidderFeedbackLeve l = '"&BuyerFeedbackScore&"', " &_
"WinningBidderID = '"&BuyerEbayID&"', AuctionPrice = '"&TransactionPrice&"', " &_
"AuctionEndDate = '"&AuctionEndTime&"', AuctionStatus = 'Winner', " &_
"Notes = Notes + '"&chr(13)&BuyerName&chr(1 3)&BuyerSt reet1&" "&BuyerStreet2&chr(13)&Buy erCityName &", " &_
""&BuyerStateOrProvince&" "&BuyerPostalCode&chr(13)& BuyerCount ry&chr(13) &BuyerPhon eNumber&ch r(13)&"' "&_
"WHERE AuctionNumber='"&eBayItemI D&"'"
Set conn = CreateObject("ADODB.Connec tion")
conn.open MM_connAuctions_STRING
conn.execute SQL
conn.close
Set conn = Nothing
'Create an invoice for each transaction using the returned data
'Create a recordset grabbing customer information based on the phone number
'returned (or assigned) above. If the number does not exist, create a customer record
'with the entered data. If the number does exist, update the current billing information
'with what the user entered.
Set rsCustomerData = Server.CreateObject("ADODB .Recordset ")
rsCustomerData.ActiveConne ction = MM_connCustomers_STRING
rsCustomerData.Source = "SELECT * FROM Customers WHERE BillingPhone = '"&BuyerPhoneNumber&"'"
rsCustomerData.CursorType = 0
rsCustomerData.CursorLocat ion = 2
rsCustomerData.LockType = 1
rsCustomerData.Open()
rsCustomerData_numRows = 0
If rsCustomerData.EOF = True Then
insertCustomerSQL = "INSERT INTO Customers (BillingName, BillingAddress1, BillingAddress2, BillingCity, BillingState, BillingZipCode, " &_
"BillingCountry, BillingPhone, ShippingPhone, ShippingName, ShippingAddress1, ShippingAddress2, " &_
"ShippingCity, ShippingState, ShippingZipCode, ShippingCountry, EmailAddress) VALUES ('"&BuyerName&"', " &_
"'"&BuyerStreet1&"', '"&BuyerStreet2&"', '"&BuyerCityName&"', '"&BuyerStateOrProvince&"' , "&BuyerPostalCode&", " &_
"'"&BuyerCountry&"', '"&BuyerPhoneNumber&"', '"&BuyerPhoneNumber&"', '"&BuyerName&"', " &_
"'"&BuyerStreet1&"', '"&BuyerStreet2&"', '"&BuyerCityName&"', '"&BuyerStateOrProvince&"' , '"&BuyerPostalCode&"', " &_
"'"&BuyerCountry&"', '"&BuyerEmail&"')"
set cmdInsertCustomer = Server.CreateObject("ADODB .Command")
cmdInsertCustomer.ActiveCo nnection = MM_connCustomers_STRING
cmdInsertCustomer.CommandT ext = insertCustomerSQL
cmdInsertCustomer.CommandT ype = 1
cmdInsertCustomer.CommandT imeout = 0
cmdInsertCustomer.Prepared = true
cmdInsertCustomer.Execute( )
set cmdInsertCustomer = Nothing
Else
set updateCustomer = Server.CreateObject("ADODB .Command")
updateCustomer.ActiveConne ction = MM_connCustomers_STRING
updateCustomer.CommandText = "UPDATE Customers SET BillingPhone = '"&BuyerPhoneNumber&"', BillingName = '"&BuyerName&"'," &_
" BillingAddress1 = '"&BuyerStreet1&"', BillingAddress2 = '"&BuyerStreet2&"', BillingCity = '"&BuyerCityName&"'," &_
" BillingState = '"&BuyerStateOrProvince&"' , BillingZipCode = '"&BuyerPostalCode&"', BillingCountry = '"&BuyerCountry&"'," &_
" ShippingPhone = '"&BuyerPhoneNumber&"', ShippingName = '"&BuyerName&"'," &_
" ShippingAddress1 = '"&BuyerStreet1&"', ShippingAddress2 = '"&BuyerStreet2&"', ShippingCity = '"&BuyerCityName&"',"&_
" ShippingState = '"&BuyerStateOrProvince&"' , ShippingZipCode = '"&BuyerPostalCode&"', ShippingCountry = '"&BuyerCountry&"',"&_
" EmailAddress = '"&BuyerEmail&"' WHERE BillingPhone = '"&BuyerPhoneNumber&"'"
updateCustomer.CommandType = 1
updateCustomer.CommandTime out = 0
updateCustomer.Prepared = true
updateCustomer.Execute()
set updateCustomer = Nothing
End If
%>
<%' WA eCart Store Cart Summary in Db
if (WA_eCart_EOF(dealsDirectC art)) then
WA_connection = MM_connInvoices_STRING
WA_table = "Invoices"
WA_redirectURL = ""
WA_indexField = "InvoiceNumber"
WA_fieldNamesStr = "ShipVia|Terms|Salesperson Name|Billi ngPhone|We bOrderNumb er|LeadSou rce|Shippi ngOverride |ShippingO verrideYes No|MiscCha rgeYesNo|M iscChargeO verrideAmt |MiscCharg eOverride"
WA_fieldValuesStr = "FedEx Ground" & "|" & "PayPal" & "|" & "Chris Myers" & "|" & "" & cStr(BuyerPhoneNumber) & "" & "|" & "" & cStr(eBayItemID) & "" & "|" & "eBay" & "|" & "" & cStr(ShippingServiceCost) & "" & "|" & "Yes" & "|" & "No" & "|" & "0" & "|" & "No"
WA_columnTypesStr = "',none,''|',none,''|',non e,''|',non e,''|none, none,NULL| ',none,''| none,none, NULL|',non e,''|',non e,''|none, none,NULL| ',none,''"
WA_sessionName = "InvoiceID"
indexFieldIndex = -1
WA_fieldValues = Split(WA_fieldValuesStr,"| ")
WA_fieldNames = Split(WA_fieldNamesStr,"|" )
WA_columns = Split(WA_columnTypesStr,"| ")
set WA_editCmd = Server.CreateObject("ADODB .Command")
updateFieldValue = ""
WA_editCmd.ActiveConnectio n = WA_connection
if (WA_redirectURL <> "" AND Request.QueryString <> "" AND Request.QueryString.Count > 0) then
if (inStr(WA_redirectURL,"?") > 0) then
WA_redirectURL = WA_redirectURL & "&"
else
WA_redirectURL = WA_redirectURL & "?"
end if
WA_redirectURL = WA_redirectURL & Request.QueryString
end if
for i = 0 to Ubound(WA_fieldNames)
if (WA_indexField = WA_fieldNames(i)) then
indexFieldIndex = i
exit for
end if
next
if (indexFieldIndex >= 0) then updateFieldValue = WA_fieldValues(indexFieldI ndex)
if (updateFieldValue = "") then updateFieldValue = cStr(Session(WA_sessionNam e))
updateColType = "none,none,NULL"
if (indexFieldIndex >= 0) then
updateColType = WA_columns(indexFieldIndex )
end if
if (updateFieldValue <> "" AND updateFieldValue <> "undefined") then
valueForWhere = WA_generateInsertParams(Ar ray(WA_ind exField), Array(updateColType), Array(updateFieldValue), -1)
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & WA_indexField & " = " & valueForWhere(2) & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB .Recordset ")
WA_eCartRecordset.ActiveCo nnection = WA_connection
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy pe = 0
WA_eCartRecordset.CursorLo cation = 2
WA_eCartRecordset.LockType = 1
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then
updateFieldValue = cStr(WA_eCartRecordset.Fie lds.Item(W A_indexFie ld).Value)
else
updateFieldValue = ""
end if
WA_eCartRecordset.Close()
end if
if (updateFieldValue <> "" AND updateFieldValue <> "undefined") then
updateParamsObj = WA_generateInsertParams(WA _fieldName s, WA_columns, WA_fieldValues, indexFieldIndex)
valueForWhere = WA_generateInsertParams(Ar ray(WA_ind exField), Array(updateColType), Array(updateFieldValue), -1)
WA_editCmd.CommandText = "update " & WA_table & " SET " & updateParamsObj(3) & " where " & WA_indexField & " = " & valueForWhere(2)
WA_editCmd.Execute()
WA_editCmd.ActiveConnectio n.Close()
else
updateFieldValue = ""
insertParamsObj = WA_generateInsertParams(WA _fieldName s, WA_columns, WA_fieldValues, -1)
WA_editCmd.CommandText = "insert into " & WA_table & " (" & insertParamsObj(1) & ") values (" & insertParamsObj(2) & ")"
WA_editCmd.Execute()
WA_editCmd.ActiveConnectio n.Close()
end if
if (indexFieldIndex < 0) then
if (updateFieldValue = "") then
obj = WA_generateWhereClause(WA_ fieldNames , WA_columns, WA_fieldValues, indexFieldIndex)
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB .Recordset ")
WA_eCartRecordset.ActiveCo nnection = WA_connection
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy pe = 0
WA_eCartRecordset.CursorLo cation = 2
WA_eCartRecordset.LockType = 1
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then Session(WA_sessionName) = WA_eCartRecordset.Fields.I tem(WA_ind exField).V alue
WA_eCartRecordset.Close()
else
Session(WA_sessionName) = updateFieldValue
end if
else
Session(WA_sessionName) = WA_fieldValues(indexFieldI ndex)
end if
if (WA_redirectURL <> "") then
Response.Redirect(WA_redir ectURL)
end if
end if
%>
<%
'Get the ItemNumber and the ControlNumber of the item sold from the auction record
Set rsItemData = Server.CreateObject("ADODB .Recordset ")
rsItemData.ActiveConnectio n = MM_connAuctions_STRING
rsItemData.Source = "SELECT ItemNumber, InventoryCode FROM Auctions WHERE AuctionNumber = '"&eBayItemID&"'"
rsItemData.CursorType = 0
rsItemData.CursorLocation = 2
rsItemData.LockType = 1
rsItemData.Open()
rsItemData_numRows = 0
ItemNumber = rsItemData("ItemNumber")
ControlNumber = rsItemData("InventoryCode" )
%>
<%
'Store cart details
if (WA_eCart_EOF(dealsDirectC art)) then
insertInvoiceItemsSQL = "INSERT INTO InvoiceItems (InvoiceNumber, ItemNumber, Quantity, Price, ScanCode) VALUES ('"&Session("InvoiceID")&" ', '"&ItemNumber&"', '"&QuantitySold&"', '"&TransactionPrice&"', '"&ControlNumber&"')"
set cmdInsertInvoiceItems = Server.CreateObject("ADODB .Command")
cmdInsertInvoiceItems.Acti veConnecti on = MM_connInvoices_STRING
cmdInsertInvoiceItems.Comm andText = insertInvoiceItemsSQL
cmdInsertInvoiceItems.Comm andType = 1
cmdInsertInvoiceItems.Comm andTimeout = 0
cmdInsertInvoiceItems.Prep ared = true
cmdInsertInvoiceItems.Exec ute()
Set cmdInsertInvoiceItems = Nothing
End If
%>
<%
Next
Set TransactionInfo = Nothing
End If
%>
<%
' WA eCart Redirect
if (dealsDirectCart_redirStr <> "") then
Response.Redirect(dealsDir ectCart_re dirStr)
end if
%>
</body>
</html>
<%
rsCustomerData.Close()
Set rsCustomerData = Nothing
%>
<%
rsItemData.Close()
Set rsItemData = Nothing
%>
Basically, the script generates an XML request and sends it off to eBay and parses the response within a loop. There are lots of other things that happen within the loop. First, all of the auction records get updated with their status information, high bidder, price, etc. After that, an invoice needs to be inserted for the order into the database. The first step here is to check the customers table to see if the phone number (what's being used as customerID) already exists. If it does, update the info with the data received. If it does not exist, create a new customer record with the data received. Moving on from there, the invoice information is inserted into the database (using 3rd party WebAssist extensions in Dreamweaver) which populates the basic information and also stores the new invoice number into a session variable which is used to populate the related field in the InvoiceItems table.
Everything is working great except that all of the items end up on one single Invoice in the system. At first I had the assumption that the Session wasn't getting updated, therefore all of the items ended up on the same invoice. However, only 1 single invoice is getting created. There should be a new invoice being created for each time through the loop and that doesn't seem to be happening.
Everything else works great. Each auction record gets updated fine. The customer information gets inserted/updated accordingly. I can't figure out why the Insert isn't looping...???
Any information would be greatly appreciated. Here is the script. Go easy on me with the sloppiness of it...I'm merely intermediate.
__________________________
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../WA_eCart/WA_eC
<!--#include file="../../WA_eCart/WA_eC
<!--#include file="../../WA_eCart/deals
<!--#include file="../../Connections/co
<!--#include file="../../Connections/co
<!--#include file="../../Connections/co
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<%
sandboxTest = 1
If sandboxTest = 1 Then
sURL = "https://api.sandbox.ebay.com/ws/api.dll"
DevID = "DEVID"
AppID = "APPID"
Cert = "CERT"
AuthToken = "TOKEN"
Else
sURL = "https://api.ebay.com/ws/api.dll"
DevID = "DEVID"
AppID = "APPID"
Cert = "CERT"
AuthToken = "TOKEN
End If
'Create eBay GetItem call
'Set buffer and expiration values
Response.Buffer = true
Response.Expires = -1500
'Send POST via MS WinHTTP Services, version 5.1
Set oWinHttp = Server.CreateObject("WinHt
'Code to grab address and phone number info
'function used to add the 0 to the front of the days in the date
Function longNow(item)
If len(item) = 1 then
longNow = "0" & item
Else
longNow = item
End if
End function
'Set the From and To times so that the script will get transactions for the past 24 hours
ModTimeFrom = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) - 1 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
ModTimeTo = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
'Create GetSellerTransactions Call
GetSellerTransactionsReque
"<GetSellerTransactionsReq
"<RequesterCredentials>" &_
"<eBayAuthToken>"&AuthToke
"</RequesterCredentials>" &_
"<DetailLevel>ReturnAll</D
"<IncludeFinalValueFee>1</
"<ModTimeFrom>"&ModTimeFro
"<ModTimeTo>"&ModTimeTo&"<
"</GetSellerTransactionsRe
'Open POST
oWinHttp.Open "POST", sURL, False
'Set necessary headers
oWinHttp.SetRequestHeader "Content-Type","text/xml"
oWinHttp.SetRequestHeader "X-EBAY-API-COMPATIBILITY-
oWinHttp.SetRequestHeader "X-EBAY-API-SESSION-CERTIF
oWinHttp.SetRequestHeader "X-EBAY-API-DEV-NAME", DevID
oWinHttp.SetRequestHeader "X-EBAY-API-APP-NAME", AppID
oWinHttp.SetRequestHeader "X-EBAY-API-CERT-NAME", Cert
oWinHttp.SetRequestHeader "X-EBAY-API-CALL-NAME", "GetSellerTransactions"
oWinHttp.SetRequestHeader "X-EBAY-API-SITEID", "0"
oWinHttp.SetRequestHeader "X-EBAY-API-DETAIL-LEVEL",
'Set time out to 60 seconds
oWinHttp.SetTimeouts 60000, 60000, 60000, 60000
'Send XML request to eBay and store response in AddItemResponse
oWinHttp.Send GetSellerTransactionsReque
GetSellerTransactionsRespo
'Write contents of the response to a file on the server
set fs=Server.CreateObject("Sc
GetSellerTransactionsRespo
set tfile=fs.CreateTextFile(Ge
tfile.WriteLine(GetSellerT
tfile.close
set tfile=nothing
set fs=nothing
'open the XML document
Set xmlDoc = Server.CreateObject("Micro
xmlDoc.Async = false
xmlDoc.Load(GetSellerTrans
'Get the value of Ack - either Success or Failure. store it in AckStatus
Set GetSellerTransactionsRespo
For Each node In GetSellerTransactionsRespo
AckStatus = node.selectSingleNode("Ack
Next
Set GetSellerTransactionsRespo
'Check if the call was successful. If failed, create a file
'and print the reason inside it. Store the file in failed folder
If AckStatus = "Failure" Then
Set fs = Server.CreateObject("Scrip
filename = Server.MapPath("eBayRespon
Set tfile = fs.CreateTextFile(filename
Set Failed = xmlDoc.selectNodes("/GetSe
For Each errorNode in Failed
tfile.WriteLine errorNode.selectSingleNode
response.Write(errorNode.s
Next
Set Failed = Nothing
Set xmlDoc = Nothing
tfile.close
Set tfile = Nothing
Set fs = Nothing
response.end
Else
'Create a function to give the variables a value of "" if the node does not exist
'in the XML response
Function TryNode(Node, Loc)
On Error Resume Next
TryNode = ""
TryNode = Node.selectSingleNode(Loc)
End Function
'Create function to generate random number in the case that a phone number isn't returned in the Shipping information
Function getRandomNumber(Length)
Dim Digit
Randomize
Do While Length > 0
Length = Length - 1
Digit = Rnd * 9.9
Digit = mid(Digit, 1, instr(Digit, ".") - 1)
getRandomNumber = getRandomNumber & Digit
Loop
End Function
'Grab the transactions data from the response and update the auction records
'for all transactions returned in the response XML
Set TransactionInfo = xmlDoc.selectNodes("/GetSe
For Each node In TransactionInfo
AmountPaid = tryNode(node, "AmountPaid")
BuyerEmail = tryNode(node, "Buyer/Email")
TransactionPrice = tryNode(node, "TransactionPrice")
BuyerFeedbackScore = tryNode(node, "Buyer/FeedbackScore")
BuyerStatus = tryNode(node, "Buyer/Status")
BuyerEbayID = tryNode(node, "Buyer/UserID")
BuyerName = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerStreet1 = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerStreet2 = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerCityName = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerStateOrProvince = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerPostalCode = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerCountry = tryNode(node, "Buyer/BuyerInfo/ShippingA
BuyerPhoneNumber = tryNode(node, "Buyer/BuyerInfo/ShippingA
If BuyerPhoneNumber <> "" Then
BuyerPhoneNumber = Replace(BuyerPhoneNumber,"
BuyerPhoneNumber = Replace(BuyerPhoneNumber,"
BuyerPhoneNumber = Replace(BuyerPhoneNumber,"
Else
'Generate Random Number to use so you can insert the order
BuyerPhoneNumber = getRandomNumber(10)
End If
eBayItemID = tryNode(node, "Item/ItemID")
ListingStatus = tryNode(node, "Item/SellingStatus/Listin
AuctionEndTime = tryNode(node, "Item/ListingDetails/EndTi
AuctionEndTime = (Left(AuctionEndTime,10))
FinalValueFee = tryNode(node, "FinalValueFee")
ShippingServiceCost = tryNode(node, "ShippingServiceSelected/S
QuantitySold = tryNode(node, "Item/SellingStatus/Quanti
'Update the auction record in Filemaker with the details returned above
SQL = "UPDATE Auctions Set WinningBidderEmailAddress = '"&BuyerEmail&"', "&_
"WinningBidderFeedbackLeve
"WinningBidderID = '"&BuyerEbayID&"', AuctionPrice = '"&TransactionPrice&"', " &_
"AuctionEndDate = '"&AuctionEndTime&"', AuctionStatus = 'Winner', " &_
"Notes = Notes + '"&chr(13)&BuyerName&chr(1
""&BuyerStateOrProvince&" "&BuyerPostalCode&chr(13)&
"WHERE AuctionNumber='"&eBayItemI
Set conn = CreateObject("ADODB.Connec
conn.open MM_connAuctions_STRING
conn.execute SQL
conn.close
Set conn = Nothing
'Create an invoice for each transaction using the returned data
'Create a recordset grabbing customer information based on the phone number
'returned (or assigned) above. If the number does not exist, create a customer record
'with the entered data. If the number does exist, update the current billing information
'with what the user entered.
Set rsCustomerData = Server.CreateObject("ADODB
rsCustomerData.ActiveConne
rsCustomerData.Source = "SELECT * FROM Customers WHERE BillingPhone = '"&BuyerPhoneNumber&"'"
rsCustomerData.CursorType = 0
rsCustomerData.CursorLocat
rsCustomerData.LockType = 1
rsCustomerData.Open()
rsCustomerData_numRows = 0
If rsCustomerData.EOF = True Then
insertCustomerSQL = "INSERT INTO Customers (BillingName, BillingAddress1, BillingAddress2, BillingCity, BillingState, BillingZipCode, " &_
"BillingCountry, BillingPhone, ShippingPhone, ShippingName, ShippingAddress1, ShippingAddress2, " &_
"ShippingCity, ShippingState, ShippingZipCode, ShippingCountry, EmailAddress) VALUES ('"&BuyerName&"', " &_
"'"&BuyerStreet1&"', '"&BuyerStreet2&"', '"&BuyerCityName&"', '"&BuyerStateOrProvince&"'
"'"&BuyerCountry&"', '"&BuyerPhoneNumber&"', '"&BuyerPhoneNumber&"', '"&BuyerName&"', " &_
"'"&BuyerStreet1&"', '"&BuyerStreet2&"', '"&BuyerCityName&"', '"&BuyerStateOrProvince&"'
"'"&BuyerCountry&"', '"&BuyerEmail&"')"
set cmdInsertCustomer = Server.CreateObject("ADODB
cmdInsertCustomer.ActiveCo
cmdInsertCustomer.CommandT
cmdInsertCustomer.CommandT
cmdInsertCustomer.CommandT
cmdInsertCustomer.Prepared
cmdInsertCustomer.Execute(
set cmdInsertCustomer = Nothing
Else
set updateCustomer = Server.CreateObject("ADODB
updateCustomer.ActiveConne
updateCustomer.CommandText
" BillingAddress1 = '"&BuyerStreet1&"', BillingAddress2 = '"&BuyerStreet2&"', BillingCity = '"&BuyerCityName&"'," &_
" BillingState = '"&BuyerStateOrProvince&"'
" ShippingPhone = '"&BuyerPhoneNumber&"', ShippingName = '"&BuyerName&"'," &_
" ShippingAddress1 = '"&BuyerStreet1&"', ShippingAddress2 = '"&BuyerStreet2&"', ShippingCity = '"&BuyerCityName&"',"&_
" ShippingState = '"&BuyerStateOrProvince&"'
" EmailAddress = '"&BuyerEmail&"' WHERE BillingPhone = '"&BuyerPhoneNumber&"'"
updateCustomer.CommandType
updateCustomer.CommandTime
updateCustomer.Prepared = true
updateCustomer.Execute()
set updateCustomer = Nothing
End If
%>
<%' WA eCart Store Cart Summary in Db
if (WA_eCart_EOF(dealsDirectC
WA_connection = MM_connInvoices_STRING
WA_table = "Invoices"
WA_redirectURL = ""
WA_indexField = "InvoiceNumber"
WA_fieldNamesStr = "ShipVia|Terms|Salesperson
WA_fieldValuesStr = "FedEx Ground" & "|" & "PayPal" & "|" & "Chris Myers" & "|" & "" & cStr(BuyerPhoneNumber) & "" & "|" & "" & cStr(eBayItemID) & "" & "|" & "eBay" & "|" & "" & cStr(ShippingServiceCost) & "" & "|" & "Yes" & "|" & "No" & "|" & "0" & "|" & "No"
WA_columnTypesStr = "',none,''|',none,''|',non
WA_sessionName = "InvoiceID"
indexFieldIndex = -1
WA_fieldValues = Split(WA_fieldValuesStr,"|
WA_fieldNames = Split(WA_fieldNamesStr,"|"
WA_columns = Split(WA_columnTypesStr,"|
set WA_editCmd = Server.CreateObject("ADODB
updateFieldValue = ""
WA_editCmd.ActiveConnectio
if (WA_redirectURL <> "" AND Request.QueryString <> "" AND Request.QueryString.Count > 0) then
if (inStr(WA_redirectURL,"?")
WA_redirectURL = WA_redirectURL & "&"
else
WA_redirectURL = WA_redirectURL & "?"
end if
WA_redirectURL = WA_redirectURL & Request.QueryString
end if
for i = 0 to Ubound(WA_fieldNames)
if (WA_indexField = WA_fieldNames(i)) then
indexFieldIndex = i
exit for
end if
next
if (indexFieldIndex >= 0) then updateFieldValue = WA_fieldValues(indexFieldI
if (updateFieldValue = "") then updateFieldValue = cStr(Session(WA_sessionNam
updateColType = "none,none,NULL"
if (indexFieldIndex >= 0) then
updateColType = WA_columns(indexFieldIndex
end if
if (updateFieldValue <> "" AND updateFieldValue <> "undefined") then
valueForWhere = WA_generateInsertParams(Ar
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & WA_indexField & " = " & valueForWhere(2) & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB
WA_eCartRecordset.ActiveCo
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy
WA_eCartRecordset.CursorLo
WA_eCartRecordset.LockType
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then
updateFieldValue = cStr(WA_eCartRecordset.Fie
else
updateFieldValue = ""
end if
WA_eCartRecordset.Close()
end if
if (updateFieldValue <> "" AND updateFieldValue <> "undefined") then
updateParamsObj = WA_generateInsertParams(WA
valueForWhere = WA_generateInsertParams(Ar
WA_editCmd.CommandText = "update " & WA_table & " SET " & updateParamsObj(3) & " where " & WA_indexField & " = " & valueForWhere(2)
WA_editCmd.Execute()
WA_editCmd.ActiveConnectio
else
updateFieldValue = ""
insertParamsObj = WA_generateInsertParams(WA
WA_editCmd.CommandText = "insert into " & WA_table & " (" & insertParamsObj(1) & ") values (" & insertParamsObj(2) & ")"
WA_editCmd.Execute()
WA_editCmd.ActiveConnectio
end if
if (indexFieldIndex < 0) then
if (updateFieldValue = "") then
obj = WA_generateWhereClause(WA_
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB
WA_eCartRecordset.ActiveCo
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy
WA_eCartRecordset.CursorLo
WA_eCartRecordset.LockType
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then Session(WA_sessionName) = WA_eCartRecordset.Fields.I
WA_eCartRecordset.Close()
else
Session(WA_sessionName) = updateFieldValue
end if
else
Session(WA_sessionName) = WA_fieldValues(indexFieldI
end if
if (WA_redirectURL <> "") then
Response.Redirect(WA_redir
end if
end if
%>
<%
'Get the ItemNumber and the ControlNumber of the item sold from the auction record
Set rsItemData = Server.CreateObject("ADODB
rsItemData.ActiveConnectio
rsItemData.Source = "SELECT ItemNumber, InventoryCode FROM Auctions WHERE AuctionNumber = '"&eBayItemID&"'"
rsItemData.CursorType = 0
rsItemData.CursorLocation = 2
rsItemData.LockType = 1
rsItemData.Open()
rsItemData_numRows = 0
ItemNumber = rsItemData("ItemNumber")
ControlNumber = rsItemData("InventoryCode"
%>
<%
'Store cart details
if (WA_eCart_EOF(dealsDirectC
insertInvoiceItemsSQL = "INSERT INTO InvoiceItems (InvoiceNumber, ItemNumber, Quantity, Price, ScanCode) VALUES ('"&Session("InvoiceID")&"
set cmdInsertInvoiceItems = Server.CreateObject("ADODB
cmdInsertInvoiceItems.Acti
cmdInsertInvoiceItems.Comm
cmdInsertInvoiceItems.Comm
cmdInsertInvoiceItems.Comm
cmdInsertInvoiceItems.Prep
cmdInsertInvoiceItems.Exec
Set cmdInsertInvoiceItems = Nothing
End If
%>
<%
Next
Set TransactionInfo = Nothing
End If
%>
<%
' WA eCart Redirect
if (dealsDirectCart_redirStr <> "") then
Response.Redirect(dealsDir
end if
%>
</body>
</html>
<%
rsCustomerData.Close()
Set rsCustomerData = Nothing
%>
<%
rsItemData.Close()
Set rsItemData = Nothing
%>
ASKER
Ok, it's gonna be later tonight before I can get back to this and try it, and I definitely will. The thing is, if the problem is simply that the Session isn't getting populated correctly each time, wouldn't each invoice still be getting created? It seems to me that in a case where the session wasn't getting updated I would end up with multiple invoices, but all of the products on the first one it created and none of the others. The only place that gets used is to insert the InvoiceNumber into the InvoiceItems table so does that really effect the creation of a new invoice all together during the loop?
When I get home tonight I'll try your suggestion. My only worry is that it'll print the same InvoiceID multiple times making us think the value isn't getting updated, when in fact it's just getting pulled from the same invoice over and over updating itself with the same number.
I could be thinking incorrectly...that's obviously why I'm here. I'll update you later tonight when I give this a shot. Thanks!
When I get home tonight I'll try your suggestion. My only worry is that it'll print the same InvoiceID multiple times making us think the value isn't getting updated, when in fact it's just getting pulled from the same invoice over and over updating itself with the same number.
I could be thinking incorrectly...that's obviously why I'm here. I'll update you later tonight when I give this a shot. Thanks!
ASKER
Ok, I need to explain a little bit more I think before I can say what happened...
In the part of the script that generates the XML request, it creates the ModTimeFrom and ModTimeTo variables and stores the date format inside them.
ModTimeFrom = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) - 2 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
ModTimeTo = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) + 1 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
It returns all transactions within these 2 days, so for ModTimeFrom you subtract how many days back you want to go, and then I just add a day to the ModTimeTo so that I'm guaranteed to get all the latest transactions.
Ok, yesterday when I was playing around with this I had it set to longNow(day(date)) - 1 so that it would basically return the past 24 hours worth of transactions. I had put in 2 test transactions in eBay sandbox within that time, so they were both coming back and looping through my script as I ran it yesterday.
Today I sit down and I added in the line you said to add for testing and ran it. Well, one of those transactions got out of the time frame, so only 1 <transaction> element was returned in the XML...so, only Invoice ID was displayed to me on screen and only 1 of the auctions was updated in the database. The invoice was created successfully, so it actually worked perfectly for that one transaction since the loop only ran one time.
Well, I changed it to go back 2 days so that it would grab both transactions again. I then ran the script again, but I hadn't deleted the invoice that was just created yet. This time it grabbed both transactions and printed the InvoiceID to the screen 2 times, both of which were the same...and they were the same as the one that had just been created by the previous run!? All 3 transactions ended up on that 1 invoice in the database.
Do you have any idea what's going on here? I'm lost. appreciate any help I can get. thanks!
In the part of the script that generates the XML request, it creates the ModTimeFrom and ModTimeTo variables and stores the date format inside them.
ModTimeFrom = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) - 2 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
ModTimeTo = year(date) & "-" & longNow(month(date)) & "-" & longNow(day(date)) + 1 & " " & longNow(hour(time)) & ":" & longNow(minute(time)) & ":" & longNow(second(time))
It returns all transactions within these 2 days, so for ModTimeFrom you subtract how many days back you want to go, and then I just add a day to the ModTimeTo so that I'm guaranteed to get all the latest transactions.
Ok, yesterday when I was playing around with this I had it set to longNow(day(date)) - 1 so that it would basically return the past 24 hours worth of transactions. I had put in 2 test transactions in eBay sandbox within that time, so they were both coming back and looping through my script as I ran it yesterday.
Today I sit down and I added in the line you said to add for testing and ran it. Well, one of those transactions got out of the time frame, so only 1 <transaction> element was returned in the XML...so, only Invoice ID was displayed to me on screen and only 1 of the auctions was updated in the database. The invoice was created successfully, so it actually worked perfectly for that one transaction since the loop only ran one time.
Well, I changed it to go back 2 days so that it would grab both transactions again. I then ran the script again, but I hadn't deleted the invoice that was just created yet. This time it grabbed both transactions and printed the InvoiceID to the screen 2 times, both of which were the same...and they were the same as the one that had just been created by the previous run!? All 3 transactions ended up on that 1 invoice in the database.
Do you have any idea what's going on here? I'm lost. appreciate any help I can get. thanks!
ASKER
It seems to me that for some reason the 3rd party behavior i'm using is only creating the 1 invoice no matter how many times through the loop it goes. Does that make any sense? I can't figure out why that would be happening, though.
ASKER
The 3rd party Insert Cart Summary behavior for dreamweaver that I'm using is actually empty during this run-time. Therefore, in the behavior options I selected to only run the insert if the eCart is empty, hense the line it creates:
if (WA_eCart_EOF(dealsDirectC art)) then
Is the cart getting populated with something along the way after the first insert, and therefore not inserting a new invoice aftewards?
if (WA_eCart_EOF(dealsDirectC
Is the cart getting populated with something along the way after the first insert, and therefore not inserting a new invoice aftewards?
Can you post a snippet of the XML ?
Just to clarify, your XML contains mulitple items. Does each item belong to a seperate invoice or does the XML contain multiple items that may or may not belong to the same invoice ? If there are items for different invoices which node in the XML differentiates between invoices ?
Just to clarify, your XML contains mulitple items. Does each item belong to a seperate invoice or does the XML contain multiple items that may or may not belong to the same invoice ? If there are items for different invoices which node in the XML differentiates between invoices ?
ASKER
Here's the entire XML that came back which includes 2 transactions:
http://angelleye.sytes.net/dealsdirect/eBayApps/auctionTools/eBayResponses/getSellerTransactionsResponse.xml
The way this particular call works, it simpy returns all transactions with auction/item/buyer information. There are different calls for creating "orders" within eBay to combine multiple transactions from the same buyer. I'll move on to that after I get this problem figured out.
For now, I'm simply trying to make this script insert a new invoice for every transaction that comes back.
http://angelleye.sytes.net/dealsdirect/eBayApps/auctionTools/eBayResponses/getSellerTransactionsResponse.xml
The way this particular call works, it simpy returns all transactions with auction/item/buyer information. There are different calls for creating "orders" within eBay to combine multiple transactions from the same buyer. I'll move on to that after I get this problem figured out.
For now, I'm simply trying to make this script insert a new invoice for every transaction that comes back.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, you're getting me close. The first time through it's running the insert just like it should, then the second time through the loop it's running the update.
Does it drop into the second block ?
if (indexFieldIndex < 0) then
if (updateFieldValue = "") then
obj = WA_generateWhereClause(WA_ fieldNames , WA_columns, WA_fieldValues, indexFieldIndex)
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB .Recordset ")
WA_eCartRecordset.ActiveCo nnection = WA_connection
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy pe = 0
WA_eCartRecordset.CursorLo cation = 2
WA_eCartRecordset.LockType = 1
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then Session(WA_sessionName) = WA_eCartRecordset.Fields.I tem(WA_ind exField).V alue
WA_eCartRecordset.Close()
else
Session(WA_sessionName) = updateFieldValue
end if
And, if so, does it drop into the If or the Else ?
if (indexFieldIndex < 0) then
if (updateFieldValue = "") then
obj = WA_generateWhereClause(WA_
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
set WA_eCartRecordset = Server.CreateObject("ADODB
WA_eCartRecordset.ActiveCo
WA_eCartRecordset.Source = sqlstr
WA_eCartRecordset.CursorTy
WA_eCartRecordset.CursorLo
WA_eCartRecordset.LockType
WA_eCartRecordset.Open()
if (NOT WA_eCartRecordset.EOF) then Session(WA_sessionName) = WA_eCartRecordset.Fields.I
WA_eCartRecordset.Close()
else
Session(WA_sessionName) = updateFieldValue
end if
And, if so, does it drop into the If or the Else ?
ASKER
Ok, so based on that I changed the line right above all that to:
if (NOT WA_eCartRecordset.EOF) then
updateFieldValue = ""
else
updateFieldValue = ""
end if
WA_eCartRecordset.Close()
And that did work! it ran INSERT INTO for both times through the loop and created seperate invoices just like it's suppose to. So, apparently the firs ttime through the loop WA_eCartRecordset was getting assigned some value? Can you tell if this is going to cause a problem for me by leaving it set to blank for both instances? I don't think it should cuz I'm not using eCart data anyway, but obviously I can't tell for sure.
if (NOT WA_eCartRecordset.EOF) then
updateFieldValue = ""
else
updateFieldValue = ""
end if
WA_eCartRecordset.Close()
And that did work! it ran INSERT INTO for both times through the loop and created seperate invoices just like it's suppose to. So, apparently the firs ttime through the loop WA_eCartRecordset was getting assigned some value? Can you tell if this is going to cause a problem for me by leaving it set to blank for both instances? I don't think it should cuz I'm not using eCart data anyway, but obviously I can't tell for sure.
The honest answer is "I have no idea". All that eCart stuff is complicated and messy, it looks like its intended to handle multiple items for the same invoice in a single file rather than multiple invoices. What you have done is basically short-circuit it to get it to do what you want.
You may run into problems later, but then again you might not. If you do then you can always come up with a more robust solution.
You may run into problems later, but then again you might not. If you do then you can always come up with a more robust solution.
ASKER
Maybe you can answer this for me. How in the heck is it grabbing the value of the InvoiceID for the brand new Invoice that it just created? That's the only reason I'm using this eCart extension to begin with...it takes care of that for me. Otherwise I could do a more simple insert like I have for the InvoiceItems.
You'd need to look at this line to see what it is putting in the WHERE clause:
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
The WA_indexField at this point will probably say "InvoiceID" so I would guess that this is the query that grabs it. Its difficult to tell from the code what it might be putting in the WHERE clause, so a bit of debug to see what it says might answer the question.
sqlstr = "select " & WA_indexField & " from " & WA_table & " where " & obj & " order by " & WA_indexField & " DESC"
The WA_indexField at this point will probably say "InvoiceID" so I would guess that this is the query that grabs it. Its difficult to tell from the code what it might be putting in the WHERE clause, so a bit of debug to see what it says might answer the question.
Response.Write "InvoiceID: " & Session("InvoiceID") & "<br>": Response.Flush
Immediately before the line:
insertInvoiceItemsSQL = "INSERT INTO InvoiceItems (InvoiceNumber, ItemNumber, Quantity, Price, ScanCode) VALUES ('"&Session("InvoiceID")&"
It should make it easier to track down the problem once we know if that value changes or not.