DynDeveloper.com

DynDeveloper.com

Sign Up Now!Log In
scotsun 5/17/2016 3:00:29 PM

When i have updated the location code in SO transaction the contact information has been modified.

I have a function to update the Location Code in a SO transaction which is working properly but the problem is that the SO transaction's contact info was changed too. I'm not even touching the sop transaction's address  fields. Maybe I have to...I don't know.

why the transaction's contact info is being modified? how is GP selecting the new contact info?
what are the minimum transactions fields do I need to specify when I want to update the SO transaction?

here is my code

 Sub ModifWarehouse(ByVal strSOPNUMBE As String, ByVal intSOPTYPE As Int16, ByVal strDOCID As String, ByVal strCUSTNMBR As String, ByVal dtDocDate As String, ByVal strBACHNUMB As String, ByVal loc As String, ByVal poNum As String)
        Try
            Dim sConnectionString = ConfigurationManager.ConnectionStrings("eConnectConnectionString").ConnectionString
            Dim intNumberOfLines As Int16 = 0 '0 = 1 line
            Dim salesOrderDocument As String
            'declare our eConnect classes
            Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
            Dim oSOPTransactionType As New Microsoft.Dynamics.GP.eConnect.Serialization.SOPTransactionType
            'this is our custom eConnect Class, you can find it here: http://dyndeveloper.com/thread.aspx?Threadid=1117
            Dim eConCall As New eConnectMethods
            'Done Serializing
            '************************* 
            ReDim Preserve oeConnectType.SOPTransactionType(0)
            oeConnectType.SOPTransactionType(0) = oSOPTransactionType

            Dim z As Integer = 0
            Dim itemList As List(Of taSopLineIvcInsert_ItemsTaSopLineIvcInsert) = ModifWarehouseInOrderLines(strSOPNUMBE, intSOPTYPE, loc, strDOCID, dtDocDate, poNum, strCUSTNMBR)


            For Each item As taSopLineIvcInsert_ItemsTaSopLineIvcInsert In itemList
                ReDim Preserve oSOPTransactionType.taSopLineIvcInsert_Items(z)
                oSOPTransactionType.taSopLineIvcInsert_Items(z) = item
                z = z + 1
            Next

            'create the document header
            Dim otaSopHdrIvcInsert As New Microsoft.Dynamics.GP.eConnect.Serialization.taSopHdrIvcInsert
            'populate the header
            With otaSopHdrIvcInsert
                'these are the required fields
                .SOPNUMBE = strSOPNUMBE
                .SOPTYPE = intSOPTYPE
                .DOCID = strDOCID
                .CUSTNMBR = strCUSTNMBR
                .DOCDATE = dtDocDate
                .BACHNUMB = strBACHNUMB
                .UpdateExisting = 1
                'this is the field that we're updating. 
                .LOCNCODE = loc
                .CSTPONBR = poNum
            End With
            'assign the header to the master
            oSOPTransactionType.taSopHdrIvcInsert = otaSopHdrIvcInsert
            ReDim Preserve oeConnectType.SOPTransactionType(0)
            oeConnectType.SOPTransactionType(0) = oSOPTransactionType

            Dim xmldoc As Xml.XmlDocument = eConnectOrderToXMLDocument(oeConnectType)
            salesOrderDocument = xmldoc.OuterXml

            eConCall.UpdateTransactionEntity(sConnectionString, salesOrderDocument)
        Catch ex As System.ServiceModel.FaultException(Of eConnectSqlErrorCollection)
            Dim strMessage = ex.Detail(0).Message
            MsgBox(ex.Message + ". In ModifWarehouse method")
        Catch ex As System.ServiceModel.FaultException(Of Microsoft.Dynamics.GP.eConnect.eConnectFault)
            Dim strMessage = ex.Detail.Message
            MsgBox(ex.Detail.Message + ". In ModifWarehouse method")
        Catch ex As Exception
            MsgBox(ex.Message + ". In ModifWarehouse method")
        Finally
        End Try
    End Sub

---------------------------------------------

Function ModifWarehouseInOrderLines(SOPNUMBE As String, SOPTYPE As Int16, ByVal newLoc As String, ByVal strDOCID As String, ByVal strDocDate As String, ByVal poNum As String, ByVal strCUSTNMBR As String) As List(Of taSopLineIvcInsert_ItemsTaSopLineIvcInsert) ' Microsoft.Dynamics.GP.eConnect.Serialization.taSopLineIvcInsert_ItemsTaSopLineIvcInsert
        Dim val As Boolean = False
        Dim itemList As New List(Of taSopLineIvcInsert_ItemsTaSopLineIvcInsert)
        Dim sConnectionString = ConfigurationManager.ConnectionStrings("eConnectConnectionString").ConnectionString
        Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
        Dim oSOPTransactionType As New Microsoft.Dynamics.GP.eConnect.Serialization.SOPTransactionType
        Try
            'get an XML document that represents the customer 
            'this uses our SalesTransactionRetrieve class documented here
            'http://dyndeveloper.com/articleview.aspx?ArticleID=173
            Dim oSalesTransactionRetrieve As New SalesTransaction
            oSalesTransactionRetrieve.retrieveSalesTransaction(SOPNUMBE, SOPTYPE)
            Dim strSOPTrans As String = oSalesTransactionRetrieve.SOPDoc

            '==========================================================
            'parse the line
            '==========================================================
            'strSOPTrans is an XML document in string form
            'parse it into XDocument form
            Dim doc = XDocument.Parse(strSOPTrans)

            'use Linq-to-XML to select just one sop line in the document. 
            Dim query = _
                From c In doc.<root>.<eConnect>.<SO_Trans>.<Line>
                Select c

            'turn it back into a string so we can edit it a little
            Dim line As String
            For Each element As System.Xml.Linq.XElement In query
                RemoveAllInecesaryNodes(element) 
                line = element.ToString
                line = Replace(line, "Line", "taSopLineIvcInsert_ItemsTaSopLineIvcInsert")

                Dim sopNumber = element.Element("SOPNUMBE").Value
                Dim qty = element.Element("QUANTITY").Value
                Dim itemnum = element.Element("ITEMNMBR").Value
                Dim PRCLEVEL = element.Element("PRCLEVEL").Value
                Dim myReader As New StringReader(line)
                'Deserialize the XML node from the StringReader into the taSopLineIvcInsert_ItemsTaSopLineIvcInsert object.
                Dim oXmlSerializer As New XmlSerializer(GetType(taSopLineIvcInsert_ItemsTaSopLineIvcInsert))
                'Cast the deserialized object to a taSopHdrIvcInsert serialization object
                Dim otaSopLineIvcInsert As taSopLineIvcInsert_ItemsTaSopLineIvcInsert = CType(oXmlSerializer.Deserialize(myReader), taSopLineIvcInsert_ItemsTaSopLineIvcInsert)
                With otaSopLineIvcInsert
                    .LOCNCODE = newLoc
                    .CUSTNMBR = strCUSTNMBR
                    .DOCID = strDOCID
                    .DOCDATE = strDocDate
                    .SOPNUMBE = sopNumber
                    .SOPTYPE = SOPTYPE
                    .QUANTITY = qty
                    .ITEMNMBR = itemnum
                    'these fields are not required, but they will be 0 or '' if the value is not set
                    .PRCLEVEL = PRCLEVEL
                    otaSopLineIvcInsert.UpdateIfExists = 1
                End With

                itemList.Add(otaSopLineIvcInsert)
            Next
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
        Return itemList
    End Function

Version: Unknown or N/A
Section: eConnect