Dears,
I have below code at service class level to bring all customer invoice details. Once I try to print in .net consle app its always reading first invoice code only. Please advice.
//Service claas [SysEntryPointAttribute(true),AifCollectionTypeAttribute("return" , Types::Class, classStr(EinvoiceLinesParam))] public List getSalesInvoices() { CustInvoiceTrans custInvoiceTrans; CustInvoiceJour custInvoiceJour; InvoiceId invoiceId; EinvoiceLinesParam esalesClassObj; List esaleslist = new List(Types::Class); TransDate d; ; d = systemDateget(); esalesClassObj = new EinvoiceLinesParam(); while select * from custInvoiceTrans join custInvoiceJour order by InvoiceId where custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId && custInvoiceTrans.InvoiceDate >= d && custInvoiceTrans.InvoiceDate <= d { if (invoiceId != custInvoiceJour.InvoiceId) { esalesClassObj.parmInvoiceDate(custInvoiceJour.InvoiceDate); esalesClassObj.parmInvoiceId(custInvoiceJour.InvoiceId); esalesClassObj.parmSalesId(custInvoiceJour.SalesId); esalesClassObj.parmCustName(custInvoiceJour.DeliveryName); esalesClassObj.parmtotalAmountWithDisc(custInvoiceJour.SumLineDisc); esalesClassObj.parmtotalSalesAmount(custInvoiceJour.SalesBalance); esalesClassObj.parmnetAmount(custInvoiceJour.SalesBalance - custInvoiceJour.SumLineDisc); esalesClassObj.parmtotalAmount(custInvoiceJour.InvoiceAmount); esalesClassObj.parmtotalItemsDiscountAmount(custInvoiceJour.SumLineDisc); } esalesClassObj.parmItemNameDisplay(custInvoiceTrans.itemName()); esalesClassObj.parmItemId(custInvoiceTrans.ItemId); invoiceId = custInvoiceJour.InvoiceId; esaleslist.addEnd(esalesClassObj); } return esaleslist; } .Net claas to print results in console class Program { static void Main(string[] args) { getEinvoiceSales() } static void getEinvoiceSales() { ServiceReference3.EinvoicesalesServiceClient serviceCLient = new EinvoicesalesServiceClient(); ServiceReference3.CallContext callCont = new ServiceReference3.CallContext(); callCont.Company = " "; serviceCLient.ClientCredentials.Windows.ClientCredential.Domain = " "; serviceCLient.ClientCredentials.Windows.ClientCredential.UserName = " "; serviceCLient.ClientCredentials.Windows.ClientCredential.Password = " "; ServiceReference3.EinvoiceLinesParam[] salesList = serviceCLient.getSalesInvoices(callCont); foreach (EinvoiceLinesParam _sales in salesList) { Console.WriteLine(_sales.internalID); //Invoiceid } Console.ReadKey(); }
Hi,
did you already debug your code to find out if the problem is in the x++ data retrieval or your C# code?
If not, please do. If you did, please let us know the results.
You should first make sure that the x++ code works as you want to, and then start working on C# side to use it.
Looking at the code, you never seem to instantiate more than one "esalesClassObj" object. So you're updating the same object again and again, and adding it to the list. This means that all entries in the list point to the one and same object, which has the values that you put there last (all previous values are overwritten when you write new values to the same object).
I'd say that you should instantiate a new object for each iteration in the while loop.
Also, do you intentionally set the data criteria to "invoice date is same or smaller than today" AND "invoice data is same or greater than today"? These two conditions together can be replaced with "invoice date is today". On the other hand, if you mean to have an OR condition, then you don't need any criteria on the date (since you would want invoices where date is smaller, same or greater than today).
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156