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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

unable to save Sales Quotation report as pdf to a local drive through x++ code

(0) ShareShare
ReportReport
Posted on by

Hi all,

Please help me out in saving the Quotation Report as pdf to a local drive.

I am getting the below error while running the job where I have written code for saving the report as pdf to a local drive.  Please let me know what am I  doing wrong ?

Please find my code as Below :

static void KTI_BusinessConnector(Args _args)
{
KTI_SalesTempQuotation kti_SalesQuotation;
Args args = new Args();
PrintJobSettings pjs = new PrintJobSettings();
SysReportRun reportRun;
filename mFile;
QuotationId qId;
;


mFile = "C:\\MyFile.pdf";
winapi::deleteFile(mFile);

pjs.fileName(mFile);
pjs.format(PrintFormat::PDF);
pjs.setTarget(PrintMedium::File);
pjs.preferredFileFormat(PrintFormat::PDF);

//Set a preferred printer so the pdf looks normal when the default of the user is
//a strange printer (like a dot matrix label printer)
// pjs.deviceName(BCSalesQuotation_v1_02::.PrinterEmulationPDF);

args.name(reportstr("BCSalesQuotation_v1_02"));

while Select forupdate kti_SalesQuotation
where kti_SalesQuotation.UserInformation == XUserInfo::find(false, curUserId()).name
{
if(kti_SalesQuotation)
{
ttsbegin;
kti_SalesQuotation.delete();
ttscommit;
}
}

kti_SalesQuotation.clear();
qId = 'QT-00085276';
//select kti_SalesQuotation;
ttsbegin;
kti_SalesQuotation.UserInformation = XUserInfo::find(false, curUserId()).name;
kti_SalesQuotation.SalesQuotationNo = qId;
kti_SalesQuotation.insert();
ttscommit;

args.record(kti_SalesQuotation);
reportRun = classFactory.reportRunClass(args);

reportRun.printJobSettings(pjs.packPrintJobSettings());
reportRun.query().interactive(false);
reportRun.report().interactive(false);
reportRun.init();
reportRun.run();
}

Error am getting as below :

 

Error:
Error executing code: The field with ID '0' does not exist in table 'CustQuotationJour'.

Stack trace

(S)\Classes\RecordSortedList\first
(C)\Reports\BCSalesQuotation_v1_02\Methods\init - line 33
(C)\Jobs\KTI_BusinessConnector - line 52

Please do the needful

Thanks and regards,

Mania

 

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code ax4

    The error says that the problem is init() method of BCSalesQuotation_v1_02 report, at line 33, therefore start your debugging there. If you don't see any problem, please show us the code of init() and share you findings with us.

    Also, please use </> button in the rich formatting view to paste source code. It makes it easier for other to read the code, which will increase your change to get an answer.

    By the way, your use of a persistent table that's cleaned up when running a report is potential dangerous. You may get into problems if the same user runs the same report twice at the same time. If you must use a persistent table, you can at least improve your code. If there is only one record per user, replace deleting and inserting with an update. If there may be more, replace while select+delete with delete_from. Also note that name isn't necessarily unique, therefore using user ID would be safer.

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Thanks  a lot for your reply.

    Please find code for init() and fetch method of my Report as below:

    init() :
    void  init()
    {;
    //MCA:PM 5/21/2010 SSRS reporting BEGIN
        if(MCASSRSReportSetup::find(MCASSRSReport::SalesQuotation).RecId)
        {
            element.callSSRSReport();
            super();
            return;
        }
    //MCA:PM 5/21/2010 SSRS reporting END
        super();
    
        printCopyOriginal = element.args().parmEnum();
    
        if (classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Sales_Send) || classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Proj_Send))
        {
            salesQuotationEditLines = element.args().caller();
        }
    
        if (element.args().record())
            journalList         = SalesQuotationEditLinesForm::createJournalListCopy(element.args().record());
        else
            journalList         = element.args().object();
    
        if (element.args().parm())
            inqueryType = element.args().parm();
        else
            inqueryType = "";
    
        if (!journalList)
            throw '';
    
        journalList.first(custQuotationJour);
    
        if (!custQuotationJour)
            throw error("@SYS26348");
    
        custFormletterDocument      = CustFormletterDocument::find();
        custFormletterParameters    = CustFormletterParameters::find();
        companyInfo                 = CompanyInfo::find();
    
        this.changeDesign();
    
        if (custFormletterParameters.TaxSpecPrintLevel != TaxSpecPrintLevel::None)
        {
            if (custFormletterParameters.TaxSpecPrintLevel == TaxSpecPrintLevel::Currency)
            {
    
            }
        }
    
        this.enableTotalsSections();
    
        inventDimReport = new InventDimCtrl_Rep_Sales(element);
        inventDimReport.parmDocumentStatus(DocumentStatus::Quotation);
        inventDimReport.parmDisableLabel(custFormletterParameters.PrePrintLevelQuotation == PrePrintLevel::PrePrinted);
        inventDimReport.initDimParmVisible();
        inventDimReport.updateControls();
        inventdimSetup = inventDimReport.dimFieldsActive(inventDimReport.parmDimParmVisible());
    
        salesFormLetterReport = SalesFormLetterReport::construct(DocumentStatus::Quotation);
        salesFormLetterReport.parmReportDesign(element);
    
    
        //Karya - Start - 11/12/2016
         //qbrReport = this.query().dataSourceName('CustQuotationTrans').addRange(fieldnum(CustQuotationTrans,ItemId));
        // qbrReport.value(queryvalue(CustQuotationTrans.ItemId));
        //Karya - End - 11/12/2016
    }
    


    fetch() :

     

    boolean  fetch()
    {
        QueryRun                tradeLoopTrans;
        boolean                 printFooters;
        int                     i,j=1,k=1;
        int                     nTransCount;
        QueryRun                testTrans;
        DocuRef                 docuRef;
        Boolean                 notes=false;
        ;
        setprefix(this.design().caption());
    
    //    PCTest = True;
        IS_OSH = False;  // Init IS_OSH
    
        while (custQuotationJour)
        {
            setprefix(strfmt("@SYS70899", custQuotationJour.QuotationId));
    
            isSummaryUpdated    = custQuotationJour.isSummaryUpdated();
    
            element.design().languageID(custQuotationJour.LanguageId);
    
            //Set the initial numnber of copies based on what the user entered
            salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
    
            if (printCopyOriginal == PrintCopyOriginal::OriginalPrint)
            {
                salesFormLetterReport.numberOfCopies(custQuotationJour.PrintCopies);
                salesFormLetterReport.numberOfOriginals(custQuotationJour.PrintOriginals);
            }
            else
                salesFormLetterReport.setPrintOriginalOrCopy(printCopyOriginal == PrintCopyOriginal::Copy);
    
            salesFormLetterReport.checkSomethingToPrint();
    
            while (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
            {
                if (salesFormLetterReport.numberOfOriginals())
                {
                    salesFormLetterReport.printingCopy(false);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings(salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Original));
                    }
                    else
                    {
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Original));
                        element.printJobSettings().setTarget(PrintMedium::Screen);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfOriginals());
                }
                else
                {
                    salesFormLetterReport.printingCopy(true);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings((salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Copy)));
                    }
                    else
                    {
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Copy));
                        element.printJobSettings().setTarget(PrintMedium::Screen);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfCopies());
                }
    
                this.send(custQuotationJour);
    
                if (docuTitle)
                    element.execute(1);
                if (docuIntro)
                    element.execute(2);
                if (docuConclusion)
                    element.execute(3);
    
                lineHeaderPrintedCount = 0;
    
                tradeLoopTrans = new TradeLoopTrans(custQuotationJour, tablenum(CustQuotationTrans)).buildQueryRun();
    //            tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addRange(FieldNum(CustQuotationTrans,QuotationDocNum))
                tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addSortField(fieldnum(CustQuotationTrans,ProjTransType),SortOrder::Descending);
                j= SysQuery::countTotal(tradeLoopTrans);
                i=0;
                while (tradeLoopTrans.next())
                {
                    testTrans = tradeLoopTrans;
                    custQuotationTrans = tradeLoopTrans.get(tablenum(CustQuotationTrans));
                    salesQuotationLine = SalesQuotationLine::findInventTransId(custQuotationTrans.InventTransId);
                    inventTable        = InventTable::find(custQuotationTrans.ItemId);
                    element.setFieldsVisible();
                    this.send(salesQuotationLine);
                    this.send(custQuotationTrans);
                    while Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationLine) &&
                                                    docuRef.RefRecId == SalesQuotationLine.RecId &&
                                                    docuRef.TypeId == "Note" &&
                                                    docuRef.Restriction == docuRestriction::External
    
                    if(docuRef.Notes)
                    {
                        notes = True;
                    }
    
                    if(notes)
                    {
                        element.execute(7);
                    }
                    i++;
                    if(i!=j)
                    {
                        element.execute(6);
                    }
                    //info(int2str(i));
                    SQID = custquotationtrans.origQuotationId;
                }
                HeaderCustQuotationTrans.height(0,units::char);
                HeaderCustQuotationTrans.lineBelow(LineType::None);
                Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationTable) &&
                                                            docuRef.RefRecId == SalesQuotationTable::find(CustQuotationJour.salesQuotationTable().QuotationId).RecId &&
                                                            docuRef.TypeId == "Note" &&
                                                            docuRef.Restriction == docuRestriction::External;
                if(docuRef.Notes)
                {
                    element.execute(8);
                    Control_4.visible(false);
                }
    
                element.execute(5);
    
                if(salesquotationtable::find(SQID).Dimension[2] == '08')
                IS_OSH = TRUE;
    
    // Portland ?
                //if(salesquotationtable::find(SQID).Dimension[2] != '07' && salesquotationtable::find(SQID).Dimension[2] != '09')
                    salesFormLetterReport.printFormLetterRemarks(custQuotationJour);
    
    
    
                salesFormLetterReport.originalOrCopyIsPrinted();
                if (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
                    element.reset();
            }
    
            if (!journalList.next(custQuotationJour))
            {
                break;
            }
            else
                element.reset();
    
            origSalesId = custQuotationTrans.OrigSalesId;
        }
    
        element.execute(4); // Comment(OSH)
        element.execute(1); // Print PCTest ?
        element.execute(2);
    
        return true;
    }
    



     

    Please help me to understand what is going wrong

  • Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Which line is throwing the error (= which line is 33)? What did you find when you debugged the code, before giving it up and asking here? Don't forget that we depend on information from you; we can't do much for you if you don't do your part.

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    in init() method , the Line "journalList.first(custQuotationJour);"

    is throwing error.

    one more help please , I m unable to understand the following lines of code  in init () method

    //MCA:PM 5/21/2010 SSRS reporting BEGIN

       if(MCASSRSReportSetup::find(MCASSRSReport::SalesQuotation).RecId)

       {

           element.callSSRSReport();

           super();

           return;

       }

    //MCA:PM 5/21/2010 SSRS reporting END

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Hi Martin,

    I have created a duplicate copy of the original report and made some changes in the init() and fetch() method of the report , and then I am able to create PDF file in the local drive but I am not able to open the file coz as I open I get error Invalid format or File corrupted . I really don't no what's happening :

    Please find the code a below :

    I have highlighted(BOLD) the lines of code which I changed.

    init()

    void  init()
    {
        KTI_SalesTempQuotation kti_SalesQuotation;
    ;
    //MCA:PM 5/21/2010 SSRS reporting BEGIN
        if(MCASSRSReportSetup::find(MCASSRSReport::SalesQuotation).RecId)
        {
            element.callSSRSReport();
            super();
            return;
        }
    //MCA:PM 5/21/2010 SSRS reporting END
        super();
    
        printCopyOriginal = element.args().parmEnum();
    
        if (classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Sales_Send) || classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Proj_Send))
        {
            salesQuotationEditLines = element.args().caller();
        }
    
        if (element.args().record())
            journalList         = SalesQuotationEditLinesForm::createJournalListCopy(element.args().record());
        else
            journalList         = element.args().object();
    
        if (element.args().parm())
            inqueryType = element.args().parm();
        else
            inqueryType = "";
    
        if (!journalList)
            throw '';
        // KTI_start - 16/7/2017
        select kti_SalesQuotation
        where kti_SalesQuotation.UserInformation == XUserInfo::find(false, curUserId()).name;
    
        select custQuotationJour
        where custQuotationJour.QuotationId == kti_SalesQuotation.SalesQuotationNo;
    
        // KTI_End - 16/7/2017
       // journalList.first(custQuotationJour);
    
        if (!custQuotationJour)
            throw error("@SYS26348");
    
        //custFormletterDocument      = CustFormletterDocument::find();
        //custFormletterParameters    = CustFormletterParameters::find();
        companyInfo                 = CompanyInfo::find();
    
        this.changeDesign();
    
        if (custFormletterParameters.TaxSpecPrintLevel != TaxSpecPrintLevel::None)
        {
            if (custFormletterParameters.TaxSpecPrintLevel == TaxSpecPrintLevel::Currency)
            {
    
            }
        }
    
        this.enableTotalsSections();
    
        inventDimReport = new InventDimCtrl_Rep_Sales(element);
        inventDimReport.parmDocumentStatus(DocumentStatus::Quotation);
        inventDimReport.parmDisableLabel(custFormletterParameters.PrePrintLevelQuotation == PrePrintLevel::PrePrinted);
        inventDimReport.initDimParmVisible();
        inventDimReport.updateControls();
        inventdimSetup = inventDimReport.dimFieldsActive(inventDimReport.parmDimParmVisible());
    
        salesFormLetterReport = SalesFormLetterReport::construct(DocumentStatus::Quotation);
        salesFormLetterReport.parmReportDesign(element);
    
    
        //Karya - Start - 11/12/2016
         //qbrReport = this.query().dataSourceName('CustQuotationTrans').addRange(fieldnum(CustQuotationTrans,ItemId));
        // qbrReport.value(queryvalue(CustQuotationTrans.ItemId));
        //Karya - End - 11/12/2016
    }
    


    fetch()

     

    boolean  fetch()
    {
        QueryRun                tradeLoopTrans;
        boolean                 printFooters;
        int                     i,j=1,k=1;
        int                     nTransCount;
        QueryRun                testTrans;
        DocuRef                 docuRef;
        Boolean                 notes=false;
        KTI_SalesTempQuotation  kti_SalesQuotation;
        Args    args=new Args("BCSalesQuotation_v1_02");
        SysReportRun reportRun ;// = new SysReportRun();
        ;
        setprefix(this.design().caption());
    
    //    PCTest = True;
        IS_OSH = False;  // Init IS_OSH
    
        // KTI_start - 16/7/2017
       while select kti_SalesQuotation
        where kti_SalesQuotation.UserInformation == XUserInfo::find(false, curUserId()).name
        {
        select custQuotationJour
        where custQuotationJour.QuotationId == kti_SalesQuotation.SalesQuotationNo;
    
        // KTI_End - 16/7/2017
        if(kti_SalesQuotation)
        {
        while (custQuotationJour)
        {
                     //   args.record(custQuotationJour);
                      //  reportRun = classFactory.reportRunClass(args);
            // KTI_Start-16/7/2017
        delete_from kti_SalesQuotation
        where kti_SalesQuotation.SalesQuotationNo == custQuotationJour.QuotationId && kti_SalesQuotation.UserInformation == XUserInfo::find(false, curUserId()).name;
            // KTI_End-16/7/2017
            setprefix(strfmt("@SYS70899", custQuotationJour.QuotationId));
    
            isSummaryUpdated    = custQuotationJour.isSummaryUpdated();
    
            element.design().languageID(custQuotationJour.LanguageId);
    
            //Set the initial numnber of copies based on what the user entered
            salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
    
            if (printCopyOriginal == PrintCopyOriginal::OriginalPrint)
            {
                salesFormLetterReport.numberOfCopies(custQuotationJour.PrintCopies);
                salesFormLetterReport.numberOfOriginals(custQuotationJour.PrintOriginals);
            }
            else
                salesFormLetterReport.setPrintOriginalOrCopy(printCopyOriginal == PrintCopyOriginal::Copy);
    
            salesFormLetterReport.checkSomethingToPrint();
    
            while (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
            {
                if (salesFormLetterReport.numberOfOriginals())
                {
                    salesFormLetterReport.printingCopy(false);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings(salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Original));
                    }
                    else
                    {
                       // args.record(custQuotationJour);
                        //element = classFactory.reportRunClass(args);
     
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Original));
                       // reportRun.printJobSettings().fileName("C:\\temp\\Bismillah.pdf");
                        element.printJobSettings().setTarget(PrintMedium::File);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfOriginals());
                }
                else
                {
                    salesFormLetterReport.printingCopy(true);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings((salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Copy)));
                    }
                    else
                    {
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Copy));
                        element.printJobSettings().setTarget(PrintMedium::File);
                       // element.printJobSettings().preferredFileFormat(printformat::PDF);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfCopies());
                }
    
                this.send(custQuotationJour);
    
                if (docuTitle)
                    element.execute(1);
                if (docuIntro)
                    element.execute(2);
                if (docuConclusion)
                    element.execute(3);
    
                lineHeaderPrintedCount = 0;
    
                tradeLoopTrans = new TradeLoopTrans(custQuotationJour, tablenum(CustQuotationTrans)).buildQueryRun();
    //            tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addRange(FieldNum(CustQuotationTrans,QuotationDocNum))
                tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addSortField(fieldnum(CustQuotationTrans,ProjTransType),SortOrder::Descending);
                j= SysQuery::countTotal(tradeLoopTrans);
                i=0;
                while (tradeLoopTrans.next())
                {
                    testTrans = tradeLoopTrans;
                    custQuotationTrans = tradeLoopTrans.get(tablenum(CustQuotationTrans));
                    salesQuotationLine = SalesQuotationLine::findInventTransId(custQuotationTrans.InventTransId);
                    inventTable        = InventTable::find(custQuotationTrans.ItemId);
                    element.setFieldsVisible();
                    this.send(salesQuotationLine);
                    this.send(custQuotationTrans);
                    while Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationLine) &&
                                                    docuRef.RefRecId == SalesQuotationLine.RecId &&
                                                    docuRef.TypeId == "Note" &&
                                                    docuRef.Restriction == docuRestriction::External
    
                    if(docuRef.Notes)
                    {
                        notes = True;
                    }
    
                    if(notes)
                    {
                        element.execute(7);
                    }
                    i++;
                    if(i!=j)
                    {
                        element.execute(6);
                    }
                    //info(int2str(i));
                    SQID = custquotationtrans.origQuotationId;
                }
                HeaderCustQuotationTrans.height(0,units::char);
                HeaderCustQuotationTrans.lineBelow(LineType::None);
                Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationTable) &&
                                                            docuRef.RefRecId == SalesQuotationTable::find(CustQuotationJour.salesQuotationTable().QuotationId).RecId &&
                                                            docuRef.TypeId == "Note" &&
                                                            docuRef.Restriction == docuRestriction::External;
                if(docuRef.Notes)
                {
                    element.execute(8);
                    Control_4.visible(false);
                }
    
                element.execute(5);
    
                if(salesquotationtable::find(SQID).Dimension[2] == '08')
                IS_OSH = TRUE;
    
    // Portland ?
                //if(salesquotationtable::find(SQID).Dimension[2] != '07' && salesquotationtable::find(SQID).Dimension[2] != '09')
                    salesFormLetterReport.printFormLetterRemarks(custQuotationJour);
    
    
    
                salesFormLetterReport.originalOrCopyIsPrinted();
                if (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
                    element.reset();
            }
    
           // if (!journalList.next(custQuotationJour))
          //  {
         //       break;
         //   }
            //else
           //     element.reset();
    
            origSalesId = custQuotationTrans.OrigSalesId;
            custQuotationJour.clear();
     
        }
    
        element.execute(4); // Comment(OSH)
        element.execute(1); // Print PCTest ?
        element.execute(2);
        //element.printJobSettings(element.packPrinterSettings());
        //element.query().interactive(false);
        //element.report().interactive(false);
       // element.init();
        //element.run();
    
        }
        }
    
        return true;
    
    }
    


    Please let me know , what ever I have commented  is causing the file to save properly?

  • Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    You didn't tell us anything about your debugging. Why? Does it mean that you don't know how to use the debugger, or you don't know what to debug?

    You see you have a problem with journalist, therefore the next logical step is checking what value is there, therefore debug the code initializing the value. By the way, an extremely valuable technique is isolating the problematic piece of code to a separate job - it makes easier to understand what's going on and it allows others to easily run your code. (I currently can't access AX and do it.)

    Regarding the code you don't understand, it would help if you told us which part you're struggling with. It checks whether there is a record in MCASSRSReportSetup and it is, it calls callSSRSReport(), then the parent method and then ends the execution, ignoring the rest of the method.

    Regarding your changes, please explain what you mean by them. Note that while duplicating a method allow you to try some changes while seeing the original method at the same time, you must remove the duplicate from the final code.

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Hi Martin,

    If don't comment those particular code then it is letting me to create pdf and store it in a local drive.

    Instead it is throwing an error stating that "There is no field with ID "0" exists in the table CustQuotationJour"

    Then I debugged and have found that as soon as the breakpoint hits th line Line " journalList.first(custQuotationJour);"

    and similarly if I don't comment the lines :

       // if (!journalList.next(custQuotationJour))

         //  {

        //       break;

        //   }

           //else

          //     element.reset();

    then flow exists out of the program.  I really don't understand.  Now I am able to save the report as pdf to my local drive, however but when I open the file it is throwing error that "Unable to open as invalid file format or file is corrupted"

  • Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Removing line of code that throws errors remove those errors, but also removes the original logic and you end up with broken program. This is not viable way of fixing errors. Please stop removing random pieces of code and go back to finding the bug in your code.

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code

    Martin,

    As you said, I have reverted my changes now again am not able to create and save the Quotation report .

    Also I debug and the error throws from the Line "journalList.first(custQuotationJour);"

    and I really don't no why the line is throwing error.

    I am pasting the error as below :


    Error:
    Error executing code: The field with ID '0' does not exist in table 'CustQuotationJour'.
    
    Stack trace
    
    (S)\Classes\RecordSortedList\first
    (C)\Reports\SalesQuotation_v1_0\Methods\init - line 33
    (C)\Jobs\KTI_BusinessConnector - line 53
    



    -------------------------------------------------------------

    Also I m pasting the original code of init() and fetch() method

    Please help me to understand what is causing the error

    void  init()
    {;
    //MCA:PM 5/21/2010 SSRS reporting BEGIN
        if(MCASSRSReportSetup::find(MCASSRSReport::SalesQuotation).RecId)
        {
            element.callSSRSReport();
            super();
            return;
        }
    //MCA:PM 5/21/2010 SSRS reporting END
        super();
    
        printCopyOriginal = element.args().parmEnum();
    
        if (classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Sales_Send) || classidget(element.args().caller()) == classnum(salesQuotationEditLinesForm_Proj_Send))
        {
            salesQuotationEditLines = element.args().caller();
        }
    
        if (element.args().record())
            journalList         = SalesQuotationEditLinesForm::createJournalListCopy(element.args().record());
        else
            journalList         = element.args().object();
    
        if (element.args().parm())
            inqueryType = element.args().parm();
        else
            inqueryType = "";
    
        if (!journalList)
            throw '';
    
        journalList.first(custQuotationJour);
    
        if (!custQuotationJour)
            throw error("@SYS26348");
    
        custFormletterDocument      = CustFormletterDocument::find();
        custFormletterParameters    = CustFormletterParameters::find();
        companyInfo                 = CompanyInfo::find();
    
        this.changeDesign();
    
        if (custFormletterParameters.TaxSpecPrintLevel != TaxSpecPrintLevel::None)
        {
            if (custFormletterParameters.TaxSpecPrintLevel == TaxSpecPrintLevel::Currency)
            {
    
            }
        }
    
        this.enableTotalsSections();
    
        inventDimReport = new InventDimCtrl_Rep_Sales(element);
        inventDimReport.parmDocumentStatus(DocumentStatus::Quotation);
        inventDimReport.parmDisableLabel(custFormletterParameters.PrePrintLevelQuotation == PrePrintLevel::PrePrinted);
        inventDimReport.initDimParmVisible();
        inventDimReport.updateControls();
        inventdimSetup = inventDimReport.dimFieldsActive(inventDimReport.parmDimParmVisible());
    
        salesFormLetterReport = SalesFormLetterReport::construct(DocumentStatus::Quotation);
        salesFormLetterReport.parmReportDesign(element);
    
    
        //Karya - Start - 11/12/2016
         //qbrReport = this.query().dataSourceName('CustQuotationTrans').addRange(fieldnum(CustQuotationTrans,ItemId));
        // qbrReport.value(queryvalue(CustQuotationTrans.ItemId));
        //Karya - End - 11/12/2016
    }
    


    fetch()

     

    boolean  fetch()
    {
        QueryRun                tradeLoopTrans;
        boolean                 printFooters;
        int                     i,j=1,k=1;
        int                     nTransCount;
        QueryRun                testTrans;
        DocuRef                 docuRef;
        Boolean                 notes=false;
        ;
        setprefix(this.design().caption());
    
    //    PCTest = True;
        IS_OSH = False;  // Init IS_OSH
    
        while (custQuotationJour)
        {
            setprefix(strfmt("@SYS70899", custQuotationJour.QuotationId));
    
            isSummaryUpdated    = custQuotationJour.isSummaryUpdated();
    
            element.design().languageID(custQuotationJour.LanguageId);
    
            //Set the initial numnber of copies based on what the user entered
            salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
    
            if (printCopyOriginal == PrintCopyOriginal::OriginalPrint)
            {
                salesFormLetterReport.numberOfCopies(custQuotationJour.PrintCopies);
                salesFormLetterReport.numberOfOriginals(custQuotationJour.PrintOriginals);
            }
            else
                salesFormLetterReport.setPrintOriginalOrCopy(printCopyOriginal == PrintCopyOriginal::Copy);
    
            salesFormLetterReport.checkSomethingToPrint();
    
            while (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
            {
                if (salesFormLetterReport.numberOfOriginals())
                {
                    salesFormLetterReport.printingCopy(false);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings(salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Original));
                    }
                    else
                    {
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Original));
                        element.printJobSettings().setTarget(PrintMedium::Screen);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfOriginals());
                }
                else
                {
                    salesFormLetterReport.printingCopy(true);
                    if (salesQuotationEditLines)
                    {
                        element.unpackPrintJobSettings((salesQuotationEditLines.findPrinterSettings(PrintSetupOriginalCopy::Copy)));
                    }
                    else
                    {
                        element.unpackPrintJobSettings(SalesQuotationEditLinesForm::getPrinterSettingsFormletter(DocumentStatus::Quotation,PrintSetupOriginalCopy::Copy));
                        element.printJobSettings().setTarget(PrintMedium::Screen);
                    }
                    salesFormLetterReport.initialPrinterCopies(element.printJobSettings().copies());
                    element.printJobSettings().copies(salesFormLetterReport.printNumberOfCopies());
                }
    
                this.send(custQuotationJour);
    
                if (docuTitle)
                    element.execute(1);
                if (docuIntro)
                    element.execute(2);
                if (docuConclusion)
                    element.execute(3);
    
                lineHeaderPrintedCount = 0;
    
                tradeLoopTrans = new TradeLoopTrans(custQuotationJour, tablenum(CustQuotationTrans)).buildQueryRun();
    //            tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addRange(FieldNum(CustQuotationTrans,QuotationDocNum))
                tradeLoopTrans.query().dataSourceTable(tablenum(CustQuotationTrans)).addSortField(fieldnum(CustQuotationTrans,ProjTransType),SortOrder::Descending);
                j= SysQuery::countTotal(tradeLoopTrans);
                i=0;
                while (tradeLoopTrans.next())
                {
                    testTrans = tradeLoopTrans;
                    custQuotationTrans = tradeLoopTrans.get(tablenum(CustQuotationTrans));
                    salesQuotationLine = SalesQuotationLine::findInventTransId(custQuotationTrans.InventTransId);
                    inventTable        = InventTable::find(custQuotationTrans.ItemId);
                    element.setFieldsVisible();
                    this.send(salesQuotationLine);
                    this.send(custQuotationTrans);
                    while Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationLine) &&
                                                    docuRef.RefRecId == SalesQuotationLine.RecId &&
                                                    docuRef.TypeId == "Note" &&
                                                    docuRef.Restriction == docuRestriction::External
    
                    if(docuRef.Notes)
                    {
                        notes = True;
                    }
    
                    if(notes)
                    {
                        element.execute(7);
                    }
                    i++;
                    if(i!=j)
                    {
                        element.execute(6);
                    }
                    //info(int2str(i));
                    SQID = custquotationtrans.origQuotationId;
                }
                HeaderCustQuotationTrans.height(0,units::char);
                HeaderCustQuotationTrans.lineBelow(LineType::None);
                Select firstonly Notes from docuRef where docuRef.RefTableId == Tablenum(SalesQuotationTable) &&
                                                            docuRef.RefRecId == SalesQuotationTable::find(CustQuotationJour.salesQuotationTable().QuotationId).RecId &&
                                                            docuRef.TypeId == "Note" &&
                                                            docuRef.Restriction == docuRestriction::External;
                if(docuRef.Notes)
                {
                    element.execute(8);
                    Control_4.visible(false);
                }
    
                element.execute(5);
    
                if(salesquotationtable::find(SQID).Dimension[2] == '08')
                IS_OSH = TRUE;
    
    // Portland ?
                //if(salesquotationtable::find(SQID).Dimension[2] != '07' && salesquotationtable::find(SQID).Dimension[2] != '09')
                    salesFormLetterReport.printFormLetterRemarks(custQuotationJour);
    
    
    
                salesFormLetterReport.originalOrCopyIsPrinted();
                if (salesFormLetterReport.stillOriginalsOrCopiesToPrint())
                    element.reset();
            }
    
            if (!journalList.next(custQuotationJour))
            {
                break;
            }
            else
                element.reset();
    
            origSalesId = custQuotationTrans.OrigSalesId;
        }
    
        element.execute(4); // Comment(OSH)
        element.execute(1); // Print PCTest ?
        element.execute(2);
    
        return true;
    }
    



     

     

  • Community Member Profile Picture
    on at
    RE: unable to save Sales Quotation report as pdf to a local drive through x++ code
    Below is the job I have created to call the report and save it as pdf to a local drive


    static void KTI_BusinessConnector(Args _args) { KTI_SalesTempQuotation kti_SalesQuotation; Args args = new Args(); PrintJobSettings pjs = new PrintJobSettings(); SysReportRun reportRun; filename mFile; QuotationId qId; str path = "C:\\"; ; winAPI::createDirectory(path); mFile =path+"TestBC.pdf"; //winapi::deleteFile(mFile); pjs.fileName(mFile); pjs.format(PrintFormat::PDF); pjs.setTarget(PrintMedium::File); // pjs.preferredFileFormat(PrintFormat::PDF); //Set a preferred printer so the pdf looks normal when the default of the user is //a strange printer (like a dot matrix label printer) pjs.deviceName("Microsoft XPS Document Writer (redirected 15)",ClassRunMode::Client); args.name(reportstr("SalesQuotation_v1_0")); while Select forupdate kti_SalesQuotation where kti_SalesQuotation.UserInformation == XUserInfo::find(false, curUserId()).name { if(kti_SalesQuotation) { ttsbegin; kti_SalesQuotation.delete(); ttscommit; } } kti_SalesQuotation.clear(); qId = 'QJ-00098483'; //select kti_SalesQuotation; ttsbegin; kti_SalesQuotation.UserInformation = XUserInfo::find(false, curUserId()).name; kti_SalesQuotation.SalesQuotationNo = qId; kti_SalesQuotation.insert(); ttscommit; args.record(kti_SalesQuotation); reportRun = classFactory.reportRunClass(args); reportRun.printJobSettings(pjs.packPrintJobSettings()); reportRun.query().interactive(false); reportRun.report().interactive(false); reportRun.init(); reportRun.run(); }



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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans