Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Only if I Close AX, it is allowing me to delete PDF from the drive

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All,

I am generating a PDF via x++ code and save it into a shared directory and once it's generated I tried to overwrite it and I could not because it is still being used by the AX , also I tried to delete the file but I can't due to same reason.

Please tell how I can achieve this.

Please see my below code :

public static void saveReport()
{
    SysReportRun                reportRun;
    filename                    mFile;
    QuotationId                 qId;
    Voucher                     custAcc;
    CustAccount                 custAccNum,loopNext;
    test_PrintDataCustPrcList   testPr;
    tmp_InventTableModule       tmpModule;
    pmf_PDFconditioner                dynaPdf;
    str                         sFileName,adobeExe;
    testFinalReport             testFinRep;
    pmf_DynaPrcList             dynaPrcList;
    System.Diagnostics.Process process;
    System.Diagnostics.ProcessStartInfo processStartInfo;
    Args args = new Args();
    boolean fileExists = false;
    PrintJobSettings pjs = new PrintJobSettings();

    str path = "\\"+"\\pmfcgrb24\\temppricelistPDF";
    #define.error("Error While Insert records in a table required to print Customer Price List")
    ;

    //winAPI::createDirectory(path);

    ttsbegin;
    delete_from testFinRep
        where testFinRep.CurUserId == XUserInfo::find(false, curUserId()).name;
    ttscommit;

    while select dynaPdf
    where dynaPdf.userName == XUserInfo::find(false, curUserId()).name
    {
            ttsbegin;
            delete_from dynaPrcList
                where dynaPrcList.UserName == XUserInfo::find(false, curUserId()).name;
            ttscommit;

            ttsbegin;
            dynaPrcList.UserName = XUserInfo::find(false, curUserId()).name;
            dynaPrcList.custAcc = dynaPdf.custAcc;
            dynaPrcList.insert();
            ttscommit;

            select testPr
                where testPr.CurUserId == dynaPdf.userName
                && testPr.tmpCustAccount == dynaPdf.custAcc;
            {
                    mFile = path+"\\"+"PioneerPriceList-"+testPr.tmpCustAccount+testPr.tmpCustName+".pdf";
                    sFileName = "PioneerPriceList-"+testPr.tmpCustAccount+testpr.tmpCustName;
                    pjs.fileName(mFile);
                    pjs.setTarget(PrintMedium::File);
                    pjs.format(PrintFormat::PDF);
                    pjs.preferredFileFormat(PrintFormat::PDF);
                    pjs.warnIfFileExists(false);
                    //args.name(reportstr("pmf_CustPrcListNewDesgn"));
                    args.name(reportstr("pmf_CustPrcListNewDesgn_V1"));

                    testFinRep = pmf_automateCustPrcList::loadPdfData(testPr.tmpCustAccount,testPr.CurUserId);

                    args.record(testFinRep);
                        reportRun = classFactory.reportRunClass(args);
                        reportRun.printJobSettings(pjs.packPrintJobSettings());
                        reportRun.report().interactive(false);
                        reportRun.init();
                        if (WinAPI::fileExists(mFile))
                        {
                            fileExists = true;

                        }
                        if (!fileExists)
                        {

                            reportRun.run();


                        }
                                          /* try
                    {
                        ttsbegin;
                        testFinRep.tmpCustName=testPr.tmpCustName;
                        testFinRep.tmpCustAccount=testPr.tmpCustAccount;
                        testFinRep.ItemId=testPr.ItemId;
                        testFinRep.tmpItemName=testPr.tmpItemName;
                        testFinRep.tmpItemGroupId=testPr.tmpItemGroupId;
                        testFinRep.tmpExtItem=testPr.tmpExtItem;
                        testFinRep.FilterDates=testPr.FilterDates;
                        testFinRep.tmpNewPriceDate=testPr.tmpNewPriceDate;
                        //testFinRep.CurUserId = XUserInfo::find(false, curUserId()).name;
                        testFinRep.CurUserId = testPR.CurUserId;
                        testFinRep.STDMinLineCharge = testPr.STDMinLineCharge;
                        testFinRep.tmpMinLotCharge = testPr.tmpMinLotCharge;
                        testFinRep.Division = testPr.Division;
                        testFinRep.Price = testPr.Price;
                        testFinRep.PriceUnit = testPr.PriceUnit;
                        testFinRep.tmpPrice = testPr.tmpPrice;
                        testFinRep.PriceDate = testPr.PriceDate;
                        testFinRep.viewPrice = testPr.viewPrice;
                        testFinRep.viewNewPrice = testPr.viewNewPrice;
                        testFinRep.priceIncreaseDate = testPr.priceIncreaseDate;
                        testFinRep.doNotPrintNewPrice = testPr.doNotPrintNewPrice;
                        testFinRep.insert();
                        ttscommit;
                    }
                    catch
                    {
                        throw error(#error);
                    }*/
              }
    }
}


All I want is I should be able to overwrite or delete the file.

Please help.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Only if I Close AX, it is allowing me to delete PDF from the drive

    To Add above. Only If I close the AX it is allowing me to delete the file

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans