Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

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

Posted on by 1,869

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

        }

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Issue with printing Customer Invoice details in .net console app from service classs

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans