Listing 1: VBScript for Example Scriptor Component '----------------------------------------------------------------------------- ' Function MSCSExecute: Main entry point for Scriptor Component '----------------------------------------------------------------------------- Function MSCSExecute(config, orderform, context, flags) '------------------------------------------------------------------------- ' Create ActiveX Data Object Connection and Recordset objects '------------------------------------------------------------------------- Set objConn = CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=Commerce; UID=sa; PWD=" Set objRS = CreateObject("ADODB.Recordset") objConn.Open '------------------------------------------------------------------------- ' Create SQL Statement using where sku in ('val1', 'val2') syntax ' and the sku values are iterated from the items in the OrderForm object '------------------------------------------------------------------------- strSQL = "Select * from eddinswear_inventory where sku in (" For Each Item In orderform.items strSQL = strSQL & "'" & Item.Value("sku") & "'," Next strSQL = Left(strSQL, Len(strSQL) - 1) ' Get rid of extra comma at end strSQL = strSQL & ")" '-------------------------------------------------------------------------- ' Initialize Recordset object with SQL statement, Connection, etc. '-------------------------------------------------------------------------- objRS.ActiveConnection = objConn objRS.Source = strSQL objRS.CursorType = 0 ' adOpenForwardOnly objRS.LockType = 2 'adLockPessimistic '-------------------------------------------------------------------------- ' Open the Recordset object which retrieves the inventory records ' matching the sku's in the OrderForm '-------------------------------------------------------------------------- objRS.Open '-------------------------------------------------------------------------- ' For each inventory record retrieved, decrement the inventory by the ' item quantity in the OrderForm. '-------------------------------------------------------------------------- While Not objRS.EOF and Not objRS.BOF intQty = GetItemQuantity(objRS.Fields("sku"), orderform) objRS.Fields("invcount") = objRS.Fields("invcount") - intQty objRS.MoveNext Wend '-------------------------------------------------------------------------- ' We're done. Take out our object garbage. '-------------------------------------------------------------------------- objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing '-------------------------------------------------------------------------- ' Never an error - we're always successful! '-------------------------------------------------------------------------- MSCSExecute = 1 End Function '------------------------------------------------------------------------------ ' Function GetItemQuantity: Determine Quantity in OrderFrom for specific sku '------------------------------------------------------------------------------ Function GetItemQuantity(sku, orderform) intQty = 0 For Each Item In orderform.items If item.Value("SKU") = sku then intQty = intQty + item.value("Quantity") End If Next GetItemQuantity = intQty End Function