Overview of Processing

The following Microsoft Visual Basic code shows the processing that occurs in three functions involved in order form integration with BizTalk Server. Note the fact that the first routine calls the second two routines in its innermost loop.

' Always call this routine when processing orders. It will
' return immediately if BizTalk PO integration is not enabled...
Sub InvokeBizTalk(ByVal mscsOrderGrp)
    Dim sOrderName, mscsOrderForm, oVendor, sXML
    Dim sVendorQualID, sVendorQualValue

    ' Do not do anything unless BizTalk PO integration is enabled...
    If dictConfig.i_BizTalkOptions = BIZTALK_PO_XFER_ENABLED Then

        ' Process each order form in the order group...
        For Each sOrderName In mscsOrderGrp.Value.OrderForms
            Set mscsOrderForm = _
                mscsOrderGrp.Value(ORDERFORMS).Value(sOrderName)

            ' Process each vendor known to the order form...
            For Each oVendor In mscsOrderForm.value("_vendors")

                ' Skip the default vendor, which
                ' is the local organization...
                If StrComp(oVendor.vendorID, DEFAULT_ORDERFORM, _
                                             vbTextCompare) <> 0 Then

                    ' Call second function defined here to
                    ' retrieve an XML string containing only
                    ' items associated with the current vendor...
                    sXML = GetXMLForVendorItems(mscsOrderForm, oVendor)

                    ' Get the vendor delivery information from
                    ' the orderform item...
                    sVendorQualID = _
                           mscsOrderForm.items( _
                                oVendor.itemindexes(0)).vendor_qual)
                    sVendorQualValue = _
                           mscsOrderForm.items( _
                                oVendor.itemindexes(0)).vendor_qual_value

                    ' Call third function defined here to submit
                    ' the single vendor PO to BizTalk Server...
                    Call SubmitUsingBizTalk(sXML, oVendor.vendorID, _
                                                     sVendorQualID, _
                                                  sVendorQualValue)
                End If
            Next
        Next
    End If
End Sub

' Returns an XML string containing the PO for the specified vendor...
Function GetXMLForVendorItems(ByVal mscsOrderForm, ByVal oVendor)
    Dim oXMLTransforms, oXMLSchema, oOrderFormXML, oXMLDoc
    Dim oNode, oAttribute
    Dim sFilePath

    ' Create a DictionaryXMLTransforms object...
    Set oXMLTransforms = _
        Server.CreateObject("Commerce.DictionaryXMLTransforms")

    ' Create a PO schema object...
    sFilePath = Server.MapPath("\" & MSCSAppFrameWork.VirtualDirectory) _
                & "\poschema.xml"
    Set oXMLSchema = oXMLTransforms.GetXMLFromFile(sFilePath)

    ' Create an XML version of the order form...
    Set oOrderFormXML = _
      oXMLTransforms.GenerateXMLForDictionaryUsingSchema(mscsOrderForm, _
                                                         oXMLSchema)

    ' Create a copy of the XML version of the order form...
    Set oXMLDoc = Server.CreateObject("MSXML.DOMDOCUMENT")
    oXMLDoc.loadXML oOrderFormXML.xml

    ' For each 'Item' node in the XML order form copy...
    For Each oNode In oXMLDoc.documentElement.childNodes
        If (oNode.nodeName = "Items") Then

            ' If this vendor ID of the 'Item' node is not the
            ' same as the passed vendor ID, discard the node...
            For Each oAttribute In oNode.Attributes
                If (oAttribute.nodeName = "vendorid") Then
                    If Not(oAttribute.nodeValue = oVendor.vendorID) Then
                        oNode.parentNode.removeChild oNode
                    End If
                    Exit For
                Else
                End If
            Next

        End If
    Next

    ' Return an XML string containing the remaining 'Item' nodes,
    ' all of which correspond to the passed vendor...
    GetXMLForVendorItems = oXMLDoc.xml
End Function

' Submit the vendor-specific PO to BizTalk Server...
Function SubmitUsingBizTalk(ByVal sXML, ByVal sVendorName, _
                            ByVal sDestQualID, ByVal sDestQualValue)
    Dim sSubmitType, sDocName
    Dim sSourceQualID, sSourceQualValue
    Dim oDBConfig, oOrg, sID, sName, sDef, oRes
    Dim oInterchange

    ' Retrieve the source BizTalk config values locally...
    sSubmitType = dictConfig.s_BizTalkSubmittypeQueue
    sDocName = dictConfig.s_BizTalkOrderDocType
    sSourceQualID = dictConfig.s_BizTalkSourceQualifierID
    sSourceQualValue = dictConfig.s_BizTalkSourceQualifierValue

    ' Create a BizTalk Interchange object and call its Submit
    ' routine using the passed and gathered parameters...
    Set oInterchange = Server.CreateObject("BizTalk.Interchange")
    oRes = oInterchange.Submit(sSubmitType, _
                               sXML, _
                               sDocName, _
                               sSourceQualID, _
                               sSourceQualValue, _
                               sDestQualID, _ 
                               sDestQualValue)
End Function

Copyright © 2005 Microsoft Corporation.
All rights reserved.