API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Update Debtor

0
When i run the code below i get the error:
the dataclass has no corresponding entity
at the line :
session.Debtor.UpdateFromData(debtordata)

Any help in regards to what i might doing wrong is appreciated.

    Public Sub UpdateEconomic(ByVal Kartotek As String)



        Select Case Kartotek
            Case Debitor
                Dim debtordata As IDebtorData
                Dim debtor As EconomicApiIDebtor
                Dim debtornr As String
                Dim Currency As ICurrency
                Dim DebtorGroup As IDebtorGroup
                Dim DebtorGroupNr As Integer
                Dim TermPayment As ITermOfPayment
                Dim OurReference As IEmployee
                Dim Attention As IDebtorContact
                Dim attentionName As String
                Dim OurRefNumber As String



                Dim ChkInt As Integer
                Dim RowCount As Integer = DtContactRowsCount
                Dim i As Integer
                i = 0

                For Each Dr In DtContactRows
                    If Dritem(Marked) Is DBNullValue Then

                    Else
                        If Dritem(Marked) = False Then
                        Else
                            debtornr = DrItem(0)
                            If debtornrLength  9 Or IntegerTryParse(debtornr, ChkInt) = False Then
                                'MsgBox(Debitor nr er ikke gyldigt)
                            Else
                                debtor = sessionDebtorFindByNumber(debtornr)
                                If debtor Is Nothing Then
                                    'MsgBox(Debitor nr    debtornr   findes ikke)
                                Else
                                    If Dritem(DebtorGroup) Is DBNullValue Then
                                        DebtorGroupNr = 1
                                    Else
                                        DebtorGroupNr = Dritem(DebtorGroup)
                                    End If
                                    DebtorGroup = sessionDebtorGroupFindByNumber(DebtorGroupNr)
                                    debtordata = sessionDebtorDataCreate(DrItem(Number), DebtorGroup, Dritem(Name), Dritem(Vatzone))
                                    debtordataName = Dritem(Name)
                                    debtordataAddress = Dritem(Address)
                                    If Dritem(Attention) Is DBNullValue Then
                                    Else
                                        attentionName = Dritem(Attention)
                                        Attention = sessionDebtorContactFindByName(attentionName)First
                                        debtordataAttention = Attention
                                    End If
                                    debtordataPostalCode = Dritem(PostalCode)
                                    debtordataCity = Dritem(City)
                                    debtordataCountry = Dritem(Country)
                                    debtordataVatZone = Dritem(VatZone)
                                    'debtordataEan = Dritem(Ean)
                                    debtordataEmail = Dritem(Email)
                                    OurRefNumber = Dritem(OurReference)
                                    OurReference = sessionEmployeeFindByNumber(OurRefNumber)
                                    debtordataOurReference = OurReference
                                    debtordataTelephoneAndFaxNumber = Dritem(TelephoneAndFaxNumber)
                                    Currency = sessionCurrencyFindByCode(Dritem(Currency))
                                    debtordataCurrency = Currency
                                    debtordataDebtorGroup = DebtorGroup
                                    TermPayment = sessionTermOfPaymentFindByName(Dritem(TermOfPayment))First
                                    debtordataTermOfPayment = TermPayment
                                    debtordataIsAccessible = True
                                    debtordataLayout = sessionTemplateCollectionFindByName(DK std m bankoplys 12 110210)First
                                    If Dritem(CreditMaximum) Is DBNullValue Then
                                    Else
                                        debtordataCreditMaximum = CDec(Dritem(CreditMaximum))
                                    End If
                                    debtordataCINumber = Dritem(VatNumber)
                                    debtordataWebsite = Dritem(Website)
                                    sessionDebtorUpdateFromData(debtordata)
                                    DrItem(Transfered) = 1
                                End If
                            End If
                            i = i + 1
                            ToolStripProgressBar1Value = 100 * i / RowCount
                            StatusStrip1Refresh()
                        End If
                    End If
                Next
                sessionDisconnect()
            Case Else
        End Select


    End Sub
created Apr 20, 2010 by Claus Aaberg
0% Accept Rate
Q 10 A 10 C 0

1 Answer

0
Hi Claus,

You're confusing creating and updating:

If the debtor DOES exist, you CREATE a DebtorData object - that's the wrong way around

What you should to for UPDATING is this:
- debtordata = session.DebtorData.GetData(debtor)
- Change properties on debtordata object
- session.Debtor.UpdateFromData(debtordata)

For CREATING, do this:
- debtordata = session.DebtorData.Create(... parameters ...)
- set properties on debtordata object
- session.Debtor.CreateFromData(debtordata)

Note in particular that creating a DebtorData object is a purely client-side operation - the debtor isn't saved in e-conomic until you call CreateFromData().


Best regards,

Christian Estrup
e-conomic
answered Apr 21, 2010 by Christian Estrup
Visma e-conomic A/S
...