How to create new file after new session of Batch Jobs ?

Hi guys!

I have project called AX PUSH Reports. I have 3 types of reports Daily, Weekly and Monthly.

The requirements is to save the Reports in designated folder that can access by the user and Email the Link/Path of the Shared folder, so that they can view and back track the reports.

Now my problem is, When the Batch Jobs Run on the given schedules, the file created last time is overwritten.

For Example in my Daily Reports:

  • SalesReport_09032017.xls - date modified Sept. 03, 2017 - date modified Sept. 04, 2017

What I want to do is to create new file every Run of Batch Jobs.

For example:

  • SalesReport_09032017.xls - date modified Sept. 03, 2017
  • SalesReport_09042017.xls - date modified Sept. 04, 2017

Please see below controller, this is what i used.

class CDRController_daily extends SrsReportRunController
{

}
public static void main(Args _args)
{
    CDRController_daily         controller = new SrsReportRunController();
    SRSPrintDestinationSettings     settings;
    date today_n = today();

    str date_n = date2Str(today_n, 321, 2, 0, 2, 0, 4);

    #File
    str fileName = strFmt('CDRDailyReport_%1', date_n);
    fileName = System.IO.Path::ChangeExtension(fileName,#xlsx);

  
    // Define report and report design to use
    controller.parmReportName(ssrsReportStr(PSDCDR_daily, CDR));

    // Change print settings as needed

        settings = controller.parmReportContract().parmPrintSettings();
        settings.printMediumType(SRSPrintMediumType::File);
        settings.fileFormat(SRSReportFileFormat::Excel);
        settings.overwriteFile(false);
        settings.fileName(@'\\192.168.3.123\ax push report\CDR\Daily\' + fileName);

    // Execute the report
    controller.startOperation();
}

Thank you in advance.

Please help…

If the file name is different, then it shouldn’t overwrite. Is it not happening in your case?

Kranti,

Sad to say, is not working…
when i set the Batch Job with Schedules and Executing, the files overwritten with the same filename…

JEMT

What happening right now is when the i set the Batch, the filename what it set is the only filename is using only therefore its only overwritten and is not creating new file for different day.

controller.JPG

The batch will not trigger the main method every time. Try moving your code(to set the file name) to run.

How to do that ???

Override run method on your controller and move your code to that method.

Can you teach how to do that ?

Thank you…

What method will i used?

Right click your class → override method → run. You already have the code to set the file name , move it to run method.
See \Classes\COSReportPrintController\run

Hi Kranthi,

FYI, i’m not using any DataContract…

anyway… can this help me ? >> Link

have you moved your code to run method?

Hi Kranti,

i move like this.

class CDRController_daily extends SrsReportRunController
{

}
public static void main(Args _args)
{

    //SRSPrintDestinationSettings     settings;
    date today_n = today();
    str date_n = date2Str(today_n, 321, 2, 0, 2, 0, 4);

    #File
    str fileName = strFmt('CDRDailyReport_%1', date_n);
    fileName = System.IO.Path::ChangeExtension(fileName,#xlsx);
    CDRController_daily::run(fileName);
    // Define report and report design to use

}
public static void run(str _filename)
{
    CDRController_daily         controller = new SrsReportRunController();
    SRSPrintDestinationSettings     settings;
    controller.parmReportName(ssrsReportStr(PSDCDR_daily, CDR));


    settings = controller.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileFormat(SRSReportFileFormat::Excel);
    settings.overwriteFile(true);
    settings.fileName(@'\\192.168.3.123\ax push report\CDR\Daily\' + _filename);

    // Execute the report
    controller.startOperation();
}

Help please

You don’t have to call the startOperation method in the run method.

If i remove that, nothings happen …
no dialog, no file, no schedule…

nothings goes out…

Hi Kranti,

Last time you told me to move the code to set the filename …

And send the code here…
And i test yester… i open the class and set the batch and recurrence. I set the schedule 12:34pm.

Then filename is CDRDailyReport_09052017.xlsx

And today im expecting to like this:

CDRDailyReport_09052017.xlsx
CDRDailyReport_09062017.xlsx

But sadly same issues again, he use the same filename and overwrite the file…

CDRDailyReport_09052017.xlsx (Date modified: 09-06-2017)

How can i solve this ? Can AX do that?
Please help.me

Re looked at your code, you haven’t move the file name creation part to run method.
str fileName = strFmt(‘CDRDailyReport_%1’, date_n);
fileName = System.IO.Path::ChangeExtension(fileName,#xlsx);
After making changes don’t forget to generate CIL

How will call the filename from run method to main method?

settings.fileName(@’\192.168.3.123\ax push report\CDR\Daily’ + fileName);