web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Issue with printing Customer Invoice details in .net console app from service classs

(0) ShareShare
ReportReport
Posted on by 1,883

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();

        }

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    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).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans