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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Salesline are coming more in SSRS REPORT

(0) ShareShare
ReportReport
Posted on by 1,836

I have made report in D365 where I want to get lines of sales order and there line amount total here 

i am getting multiple line but actually that sales order having one line can anyone suggest what i have made wrong in my code .

here is my code

[DataContractAttribute]
class Dev_CustomInvoiceContract
{
    CustInvoiceId    InvoiceId;

    [DataMemberAttribute(identifierStr(CustInvoiceId))]
    public  CustInvoiceId  parmCustInvoiceId ( CustInvoiceId   _CustInvoiceId  = InvoiceId)
    {
        InvoiceId = _CustInvoiceId;
        return   InvoiceId;
    }

}

class Dev_CustomInvoiceController  extends SrsReportRunController
{
    Dev_CustomInvoiceContract               Contract;
    CustInvoiceJour                         dataTableOne;

    protected void prePromptModifyContract()
    {
        //super();
        if (this.parmArgs() && this.parmArgs().record())
        {
            contract = this.parmReportContract().parmRdpContract() as Dev_CustomInvoiceContract;
            datatableone = this.parmArgs().record();
            contract.parmCustInvoiceId(dataTableOne.InvoiceId);

        }

    }

    static void main(Args args)
    {
        CustInvoiceJour                   dataTableOne;
        Dev_CustomInvoiceController       ssrsController;
        datatableone =    args.record() as   CustInvoiceJour ;
        ssrsController=  new  Dev_CustomInvoiceController();
        ssrsController.parmReportName(ssrsReportStr(Dev_CustomInvoiceReport,PrecisionDesign1 ));
        ssrsController.parmArgs(args);
        ssrsController.parmShowDialog(false);
        //ssrsController.parmLoadFromSysLastValue(false);
        ssrsController.startOperation();
    }

}

[SRSReportParameterAttribute(classstr(Dev_CustomInvoiceContract))]
class Dev_CustomInvoiceDP   extends SRSReportDataProviderBase
{
    Dev_CustomInvoiceHeader        dev_CustomInvoiceHeader;
    Dev_CustomInvoiceLine          dev_CustomInvoiceLine;

    [SrsReportDataSetAttribute(tableStr('dev_CustomInvoiceHeader'))]
    public dev_CustomInvoiceHeader  getdev_CustomInvoiceHeader()
    {
        select * from dev_CustomInvoiceHeader;
        return        dev_CustomInvoiceHeader;
    }

    [SrsReportDataSetAttribute(tableStr('dev_CustomInvoiceLine'))]
    public dev_CustomInvoiceLine getdev_CustomInvoiceLine()
    {
        select * from dev_CustomInvoiceLine;
        return        dev_CustomInvoiceLine;
    }

    public void processReport()
    {   
        CustInvoiceJour       objcustInvoiceJour;
        Salestable            objSalestable;
        SalesOrderExim 		  objsalesOrderExim;
        SalesOrderEximLines   objSalesOrderEximLines;

        Dev_CustomInvoiceContract contract = this.parmDataContract();
        str 20 InvoiceId = contract.parmCustInvoiceId();


        Query q = new Query();
        QueryBuildDataSource qbdsCustInvoiceJour  = q.addDataSource(tableNum(CustInvoiceJour));
        QueryBuildDataSource qbdsSalestable       = qbdsCustInvoiceJour.addDataSource(tableNum(Salestable));
        qbdsSalestable.addLink(fieldNum(CustInvoiceJour, SalesId),fieldNum(Salestable, SalesId));
        qbdsSalestable.joinMode(JoinMode::InnerJoin);
        //qbdsSalestable.relations(true);
        QueryBuildDataSource  qbdsSalesOrderExim  = qbdsSalestable.addDataSource(tableNum(SalesOrderExim));
        qbdsSalesOrderExim.relations(true);

        if (InvoiceId != "")
        {
            QueryBuildRange qbr    = qbdsCustInvoiceJour.addRange(fieldNum(CustInvoiceJour , InvoiceId));
            qbr.value(queryValue(InvoiceId));
        }



        QueryRun qr = new QueryRun(q);

        while(qr.next())
        {

            SalesLine                 objsalesLine;
            objcustInvoiceJour       = qr.get(tableNum(CustInvoiceJour));
            objSalestable            = qr.get(tableNum(SalesTable));
            objSalesOrderExim		 = qr.get(tableNum(SalesOrderExim));
            //objSalesOrderEximLines   = qr.get(tableNum(SalesOrderEximLines));

            {    
                
                dev_CustomInvoiceHeader.Buyer                      =       objSalestable.SalesName;
                dev_CustomInvoiceHeader.Exporter                   =       companyinfo::find().Name;
                dev_CustomInvoiceHeader.InvoiceId                  =       objcustInvoiceJour.InvoiceId;
                dev_CustomInvoiceHeader.InvDate                    =       objcustInvoiceJour.InvoiceDate;
                dev_CustomInvoiceHeader.ExporterRefrenceNumber     =       objSalesOrderExim.ExporterRefrenceNumber;
                dev_CustomInvoiceHeader.BuyersOrderNumber          =       objSalesOrderExim.BuyersOrderNumber;
                dev_CustomInvoiceHeader.BUYEROrderDate             =       objSalesOrderExim.ToDate;
                dev_CustomInvoiceHeader.Consignee                  =       objSalesOrderExim.Consignee;
                dev_CustomInvoiceHeader.PreCarrigeby               =       objSalesOrderExim.PreCarrigeby;
                dev_CustomInvoiceHeader.PlaceOfReceipt             =       objSalesOrderExim.PlaceOfReceipt;
                dev_CustomInvoiceHeader.CountryOfOriginOfGoods     =       LogisticsAddressCountryRegionTranslation::find(objSalesOrderExim.CountryOfOriginOfGoods).ShortName;
                dev_CustomInvoiceHeader.CountryOfFinalDestination  =       LogisticsAddressCountryRegionTranslation::find(objSalesOrderExim.CountryOfFinalDestination).ShortName;;
                dev_CustomInvoiceHeader.VesselFlightNo             =       objSalesOrderExim.VesselFlightNo;
                dev_CustomInvoiceHeader.PortOfLoading              =       objSalesOrderExim.PortOfLoading;
                dev_CustomInvoiceHeader.TermsOfDelivery            =       objSalestable.GetdlvTxt();
                dev_CustomInvoiceHeader.Payment                    =       PaymTerm::txt(objSalesOrderExim.Payment);
                dev_CustomInvoiceHeader.PortofDischarge            =       objSalesOrderExim.PortofDischarge;
                dev_CustomInvoiceHeader.FinalDestination           =       objSalesOrderExim.FinalDestination;
                dev_CustomInvoiceHeader.ExporterBankDetails        =       objSalesOrderExim.ExporterBankDetails;
                dev_CustomInvoiceHeader.insert();

                while select * from objSalesOrderEximLines
                    join objsalesLine
                    where objsalesLine.RecId == objSalesOrderEximLines.RefRecId
                    join  objSalestable
                    where objSalestable.SalesId == objsalesLine.SalesId
                    join objcustInvoiceJour
                    where objSalestable.SalesId == objcustInvoiceJour.SalesId

                {
                    dev_CustomInvoiceLine.DescriptionOfGoods =   objsalesLine.itemName();
                    dev_CustomInvoiceLine.SalesQty           =   objsalesLine.SalesQty;
                    dev_CustomInvoiceLine.SalesPrice         =   objsalesLine.SalesPrice;
                    dev_CustomInvoiceLine.LineAmount         =   objsalesLine.LineAmount;
                    dev_CustomInvoiceLine.HSNCode            =   objSalesOrderEximLines.HSNCode;
                    dev_CustomInvoiceLine.MarksAndNumber     =   objSalesOrderEximLines.MarksAndNumber;
                    dev_CustomInvoiceLine.KindsOfPackage     =   objSalesOrderEximLines.KindsOfPackage;
                    dev_CustomInvoiceLine.TotalCartons       =   objSalesOrderEximLines.TotalCartons;
                    dev_CustomInvoiceLine.NetWeight          =   objSalesOrderEximLines.NetWeight;
                    dev_CustomInvoiceLine.GrossWeight        =   objSalesOrderEximLines.GrossWeight;
                    dev_CustomInvoiceLine.Variation          =   objSalesOrderEximLines.Variation;
                    dev_CustomInvoiceLine.insert();
                }

            }
        }
    }

}

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    Debug your code to find where the problem occurs. I see two potential places in processReport(). You get unexpected records either from your query (for CustInvoiceJour etc.), or the while select (for objSalesOrderEximLines etc.).

    Your current issue may be caused by something else, but I see a problem with your join to CustInvoiceJour. If the lines comes from an order with several invoices, the line will be returned multiple times. Also, your current code may fail to find an existing invoice, if the invoice include several orders. The right join is through CustInvoiceSalesLink table.

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi  Martin ,

     thanks for reply ,

    I have pass the existing invoice to the while loop now i am getting exact output as i wanted.

    thanks for helping me out.

    regards ,

     Dinesh 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 545 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 408

#3
Adis Profile Picture

Adis 267 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans