Order Form Integration

Order form integration is the process of splitting an order form into multiple purchase orders and sending them to the relevant vendors using Microsoft BizTalk Server. The following aspects of this process need to be considered:

  • Associating a Vendor ID with each Catalog

  • Configuring Commerce Server for Order Form Integration

  • Overview of Processing

Associating a Vendor with each Catalog

By associating a vendor ID with each product catalog, the vendor for any given product in an order can be determined by identifying the product catalog associated with the product, and then identifying the vendor associated with that catalog. Being able to determine the vendor associated with each product allows Commerce Server to construct purchase orders on a vendor-by-vendor basis, and deliver those purchase orders to the corresponding vendors using BizTalk Server.

The process of associating vendors with catalogs is typically done manually, using Commerce Server Business Desk. For more information about assigning a vendor to each catalog, see Setting Up Your Catalogs for BizTalk Server.

Commerce Server also provides a Component Object Model (COM) object designed to allow programmatic assignment of vendors to catalogs. This object also provides methods to, for example, retrieve a list of available vendors, and return vendor information given a particular catalog. For more information about this object, see CatalogToVendorAssociation Object.

Configuring Commerce Server for Order Form Integration

The Commerce Server Solution Sites include conditional code for submitting per-vendor purchase orders to BizTalk Server, allowing these purchase orders to be sent to the relevant vendors. This functionality is built into the Solution Sites, and is configured using the Commerce Server Manager. For more information about how to configure a Commerce Server Solution Site to create purchase orders for each vendor associated with a product in an order form, see Configuring Commerce Server to Work with BizTalk Server.

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 annotations in bold italics, and 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


All rights reserved.