vmanfredi 4/7/2016 6:44:20 AM

update a sales order with tracking

Hi we are getting an error trying to update a sales order with the tracking number. Any help would be appricated

 Thanks

Vic

 

the inner exception is this

Object reference not set to an instance of an object.
at Microsoft.Dynamics.GP.BusinessLogic.FilterUpdateList[T](List`1 newList, List`1 originalList)

   at Microsoft.Dynamics.GP.SalesDocumentDefaultStrategyImplementation.FilterTrackingNumbers()

   at Microsoft.Dynamics.GP.SalesDocumentDefaultStrategyImplementation.DefaultingForUpdate(Object sender, BusinessObjectUpdateEventArgs e)

   at Microsoft.Dynamics.GP.SalesDocumentDefaultStrategy.DefaultingForUpdate(Object sender, BusinessObjectUpdateEventArgs e)

the exception detail is

Exception has been thrown by the target of an invocation.

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

   at System.Delegate.DynamicInvokeImpl(Object[] args)

   at Microsoft.Dynamics.Common.EventManager.RaiseEvent(Object source, String targetName, String eventName, EventArgs args)

   at Microsoft.Dynamics.Common.BusinessEventManager.RaiseEvent(Object source, String eventName, BusinessObjectEventArgs args)

   at Microsoft.Dynamics.Common.BusinessService.Update(BusinessObject businessObject, Context context, Policy policy)

 

 

The code is this

Imports WS_CompanyName.CompanyName
Imports System.ServiceModel
Module SendTracking


    Public Sub SendTracking()
        Dim SalesOrderNumber As String = "235119"
        Dim TrackNums() As String = {"664496187640"}
        Dim companyKey As CompanyKey
        Dim context As Context

        Dim UpdSalesOrderPolicy As Policy
        Dim wsDynamicsGP As New DynamicsGPClient
        Dim myCred As System.Net.NetworkCredential = New System.Net.NetworkCredential(Credentials go here removed by author)
         wsDynamicsGP.ClientCredentials.Windows.ClientCredential = myCred

        ' Create a context with which to call the service
        context = New Context()
        ' Specify which company to use (sample company)
        companyKey = New CompanyKey()
        companyKey.Id = (3)
        ' Set up the context object
        context.OrganizationKey = CType(companyKey, OrganizationKey)
        UpdSalesOrderPolicy = wsDynamicsGP.GetPolicyByOperation("UpdateSalesOrder", context)
        Dim SlsTrackNums(1) As SalesTrackingNumber
        Dim Indx As Integer = 0
        For Each strTrack As String In TrackNums
            SlsTrackNums(Indx) = New SalesTrackingNumber()
            SlsTrackNums(Indx).DeleteOnUpdate = True
            SlsTrackNums(Indx).Key = New SalesTrackingNumberKey()
            SlsTrackNums(Indx).Key.Id = strTrack
            SlsTrackNums(Indx).Key.SalesDocumentKey = New SalesDocumentKey()
            SlsTrackNums(Indx).Key.SalesDocumentKey.Id = SalesOrderNumber
        Next

        Dim SO As New SalesOrder()
        SO.BatchKey = New BatchKey
        SO.BatchKey.CompanyKey = companyKey
        SO.BatchKey.Id = "20160406"
        SO.TrackingNumbers = SlsTrackNums
        SO.Key = New SalesDocumentKey()
        SO.Key.Id = SalesOrderNumber
        Dim InvDate As Date = DateTime.Now
        SO.ActualShipDate = InvDate.ToShortDateString()
        SO.InvoiceDate = InvDate.ToShortDateString()
        SO.LineTotalAmount = MakeMoneyAmtObj("29.00")
        SO.FreightAmount = MakeMoneyAmtObj("4.50")
        SO.ShippingProcessStatus = ShippingProcessStatus.Shipped
        SO.TotalAmount = MakeMoneyAmtObj("33.50")
    
        Dim PO As SalesDocument

        wsDynamicsGP.UpdateSalesOrder(SO, context, UpdSalesOrderPolicy) ERROR OCCURS HERE WHILE STEPPING THROUGH THE CODE
         wsDynamicsGP.Close()
    End Sub
    Private Function MakeMoneyAmtObj(ByVal DollarAmount As String) As WS_CompanyName.CompanyName.MoneyAmount
        Dim dblAmount As Double = 0
        If Double.TryParse(DollarAmount, dblAmount) = False Then
            Console.WriteLine("Error converting " & DollarAmount & " to a double, GP2013_Invoices.MakeMoneyObj")
            End
        End If
        Dim SubTtl As New WS_CompanyName.CompanyName.MoneyAmount
        SubTtl.Currency = "USD"
        SubTtl.DecimalDigits = "2"
        SubTtl.Value = dblAmount
        Return SubTtl
    End Function
End Module

Version: GP 2013
Section: .NET Development, Dynamics GP, eConnect, Web Services


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3