How Can We Help?
Save and Organize Report by Date and Time
Purpose of this article
This article aims to show how to save a report in folders organized by years and months and put date and time in the name of the generated file.
1. Creating a report
- In this article, we will create a simple report to show the configuration step by step. Therefore, I created a new application, and then create a new report called “Reports1”.
- In the editing area, insert a text called “Report” and below it, insert another textbox object associated with the @DateTime tag.
- Create a new screen and insert a button.
- Select the button and insert the script below in the mouseup event:
Note: When inserting the script, create a new tag “@CurrentMonth” as “String”.
int month = @Month;
// Check the current month
switch(month)
{
case 1:
@CurrentMonth = "January";
break;
case 2:
@CurrentMonth = "February";
break;
case 3:
@CurrentMonth = "March";
break;
case 4:
@CurrentMonth = "April";
break;
case 5:
@CurrentMonth = "May";
break;
case 6:
@CurrentMonth = "June";
break;
case 7:
@CurrentMonth = "July";
break;
case 8:
@CurrentMonth = "August";
break;
case 9:
@CurrentMonth = "September";
break;
case 10:
@CurrentMonth = "October";
break;
case 11:
@CurrentMonth = "November";
break;
case 12:
@CurrentMonth = "December";
break;
}
//Creates the path to use when saving the report.
string path = SVApplications.ProjectPath()+"Reports\\"+@Year+"\\"+@currentMonth;
//If the directory does not exist, it creates it with the correct year and month
if(!SVFile.DirectoryExists(path))
{
SVFile.CreateDirectory(path);
}
SVReport.SaveFile("Reports1",path+"\\Reports"+@year+@month+@day+"_"+@hour+@Minute+@Second+".pdf");
- After doing that, save the screen, and add the screen as the application’s home screen.
- start the application and click on the button to run the script.
When accessing the application’s report folder, a folder was created with the current annual report. Inside the year folder, another folder was created with the current month and inside that folder a .pdf file was created with the name of the report and the date and time the file was generated.