File is already exist ! Batch Jobs Report

Hi Guys,

I need some help.

The activity i’m doing is Batch Jobs Report (Recurrence, Destination)

i set schedule in my report with specific time and day and also set the destination file.

but i encountered a problem says: “The file is already exist in path…”

the file is not overwrite, how do i know the date and the records inside.

How can i solve this?
Or how programatically change the file name like this “Filename_dateGenerated.xlsx”
or may be overwrite the existing file?

Thank you in advance!

SRSPrintDestinationSettings.fileName() allow you to set a specific name.
You may want to use something like System.IO.Path::GetTempFileName() to get a unique temporary file name.
Always using the same file and overwriting it wouldn’t work well in systems when the same report can be printed concurrently by several users.

Thank you Martin for your response.

i get what you saying, but honestly i don’t what to do or apply what you saying.

can you please teach me?

sorry. Thank you.

You didn’t say which part you’re struggling with, so I’ll assume it’s the first one - setting the name via SRSPrintDestinationSettings.fileName(). If you put SRSPrintDestinationSettings.fileName to a search engine, you’ll find a plenty of examples. Here is one in my blog.

Hi Martin.

i read the link you’ve give, i edit it and i have several questions.

SrsReportRunController          controller = new SrsReportRunController();
SRSPrintDestinationSettings     settings;
 
// Define report and report design to use
controller.parmReportName(ssrsReportStr(PurchaseOrderReport, Purchase));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
// Suppress report dialog
controller.parmShowDialog(false);
 
// Explicitly provide all required parameters
//rdpContract.parmReportStateDate(systemDateGet());
//controller.parmReportContract().parmRdpContract(rdpContract);
 
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::Excel);
settings.fileName(@'\\share\PurchaseOrder.xlsx');
 
// Execute the report
controller.startOperation();

I did not use a Data Contract, its because i set the range like this…

qbr = SysQuery::findOrCreateRange(query.datasourceTable(tableNum(PurchTable)),fieldNum(PurchTable, CreatedDateTime));
    qbr.value(SysQuery::range(dateStartMth(dateStartMth(systemDateGet())-1),dateStartMth(systemDateGet())-1));

Questions:

  1. where do i put or how to use ? sorry

  2. how to set schedule with this code? because i want to set the every 1st day of the month.
    controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);

  3. And how will the filename would like this, reason is to save all file for validation purposes.
    PurchaseOrder_June2017.xlsx

PurchaseOrder_July2017.xlsx

i hope you understand what i’m saying. sorry for everything.

thank you for time and effort.

Regards,

Jhon Edmar

Hi Martin,

I know now how to use the Controller.

Thank you…

i only have one problem, on how to set the filename like the example below.

Ex.

Filename_July2017.xlsx

TIA

TransDate t = systemDateGet();

info(strFmt(“Filename_%1%2”,mthName(mthOfYr(t)),year(t)));

Hi metin,

how about in settings.fileName("")

Try this,

#File
str fileName = strFmt(‘File_%1%2’, mthName(mthOfYr(systemDateGet())), year(systemDateGet()));
fileName = System.IO.Path::ChangeExtension(fileName,#xlsx);
info(fileName);

Hi Kranthi,

how about the path …
settings.fileName(@’\192.168.3.123\ax push report\PSD\PurchaseOrderReport.xlsx’);

Hi Kranthi,

here’s my code:

 PurchaseOrderController          controller = new SrsReportRunController();
    SRSPrintDestinationSettings     settings;
    #File
    str fileName = strFmt('PurchaseOrderReport%1%2', mthName(mthOfYr(systemDateGet())), year(systemDateGet()));
    
    fileName = System.IO.Path::ChangeExtension(fileName,#xlsx);
    
    info(fileName);

    // Define report and report design to use
    controller.parmReportName(ssrsReportStr(PurchaseOrderReport, Purchase));

    // Use execution mode appropriate to your situation
    controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
    // Suppress report dialog
    controller.parmShowDialog(false);

    //Explicitly provide all required parameters
    //rdpContract.parmReportStateDate(systemDateGet());
    //controller.parmReportContract().parmRdpContract(rdpContract);

    // 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\PSD\' + fileName);

    // Execute the report
    controller.startOperation();

Is that not working?
You can have the filePath as setup rather than hard coding and use the below code.
fileName = System.IO.Path::Combine(yourPath, fileName);

Hi Kranthi,

actually it works … sorry…

Thank you guys for your help.

This is much appreciated …

Edmar

Hi Jemt,

settings.fileName(strFmt(@"\share\PurchaseOrder%1%2.xlsx",mthName(mthOfYr(t)),year(t))

Note that, I didn’t tested code, mightly syntax error(s).