Normal Topic Report Name Utilities Needed (Read 3039 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Report Name Utilities Needed
Mar 18th, 2005 at 12:46am
Print Post Print Post  
Is there a way for us to select the name of a report.htm file either at runtime or in programming for the report?

Is there a way for us to dynamically define/override the report destination path?  There is a variable SESAME_REPORT_PATH but that would seem to be a static value.  I am looking for something that can be defined at time of report. 

This issue is created by Sesame's naming of reports.  Reports are named like ReportName_Date_Time.htm.

I want to attach/imbed a report to an Outlook email.  I can do that with no problem when I know the name of the file to be attached/imbedded.  But I need to know the name of the report. 

Suppose I did a Report Preview before using my command button.  Then I have a report there.  Suppose I modify the report a few times, now I have multiple reports there.  And finally when I click on the command button, I have one more.  All names have same "ReportNameHeader_Date", but "_Time" is different.

I have a command button that prints the report and then opens up Outlook with the report as an attachment (or imbedded).  This works good with tests that assume I know the report name.

The problem is that when the first part sends the report, I do not know its real name.  My thought to solve this was to delete old reports named report*.htm, run the report, rename the report_date_time.htm  to report.htm and have that hardcoded report.htm in my code as an attachment.

To do this, then:
I need to delete some files if they exist.
I need to rename some files if they exist.
I need error traps if they do not exist.

Looking at FileDelete() and IfFileExists.  Using them as they are for specific files is straightforward.  And I can use @Shell to rename specific files.  But the problem I need to tackle is when the file names are unknown, and need to use wildcards.  Will wildcards work with these commands?

I can probably create some batch files to use wildcards, but I don't want to worry about installing batch files in correct locations for all users in a network environment.  would prefer to stay with SesameBasic code.

There may be a way to search for all files in the directory, and parse them somehow to find the file with the correct ReportNameLeader" and then find the latest time.

Before I start to see what I can do, can anyone let me know if it will be possible?  I hope to deal with this later tonight.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Report Name Utilities Needed
Reply #1 - Mar 19th, 2005 at 10:11pm
Print Post Print Post  
Bob,

This looks to be doable using the File commands. FOr example, below is a routine that I used in the On Element Entry event of a command button to return the name of the most recently run report.

Code
Select All
var vRun as Int
var vReport as String

Function FindReport(vReportName as String) as String
var vRet as String
var vLoop as Int
var vOuterLoop as Int
var vStopOuter  as Int
var vQuit as Int
var vTime as String
var vDate as String
var vPrefix as String
var vFullReportName as String
// My reports all go to SESAME_REPORT_PATH
var vReportPath as String = "C:\SesameReports\"

	vRet = ""

	// Get the current time
	vTime = @Str(@Time)

	// Get the current date
	vDate = @Str(@Date)

	// Assemble the report filename up to the hour
	// C:\SesameReports\ReportName_2005_03_18_16_
	vPrefix = 	vReportPath
			+ vReportName
			+ "_"
			+ @Left(vDate, 4)
			+ "_"
			+ @Mid(vDate, 6, 2)
			+ "_"
			+ @Right(vDate, 2)
			+ "_"
			+ @Left(vTime, 2)
			+ "_"

	// Initialize Quit variable so we can stop
	// if we find the report
	vQuit = 0

	// Start looking at the current minute
	vOuterLoop = @ToNumber(@Right(vTime, 2))

	// Stop if we don't find a report by the right
	// name run within the past 5 minutes.
	vStopOuter = vOuterLoop - 5

	// Loop backwards through the minutes
	While((vOuterLoop >= vStopOuter) And (vQuit = 0))
	{
		// Count backwards from 60 tacking seconds
		// onto the report name until we find a match
		vLoop = 60
		While((vLoop > -1) And (vQuit = 0))
		{
			// Complete the report name with the minutes
			// and seconds and extension
			// C:\SesameReports\ReportName_2005_03_18_16_32_18.htm
			vFullReportName = 	vPrefix
						+ @Text(2 - @Len(@Str(vOuterLoop)), "0")
						+ @Str(vOuterLoop)
						+ "_"
						+ @Text(2 - @Len(@Str(vLoop)), "0")
						+ @Str(vLoop)
						+ ".htm"

			// If we find a match, quit and return
			// the filename
			If FileExists(vFullReportName)
			{
				vQuit = 1
				vRet = vFullReportName
			}
			vLoop = vLoop - 1
		}
		vOuterLoop = vOuterLoop - 1
	}

	Return(vRet)

End Function

	// Run the report
	vRun = @SelectTreeItem("Search Update Menu!Results Commands!Reports!Customers!NewReport (Preview)")

	// Get the report name. If vReport = "", then
	// no matching report was found.
	vReport = FindReport("NewReport")
	If @Len(vReport) > 0
	{
		// Do Outlook stuff
	}
	Else
	{
		@MsgBox("NO REPORT FOUND!", "", "")
	}
 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Report Name Utilities Needed
Reply #2 - Mar 20th, 2005 at 12:54am
Print Post Print Post  
Just saw your code Erika. 

Thanks once again for your efforts.

I will definitely be looking at this over the weekend.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Report Name Utilities Needed
Reply #3 - Mar 20th, 2005 at 5:05am
Print Post Print Post  
Grin
Works great!  Thanks again...

I installed in Samples\Customers, same as designed against for quick test.  Only changes I had to make was to hard code the Report Path (mine also go to Report Path Variable), and added this line for easy validation.
Quote:
  If @Len(vReport) > 0
{
@MsgBox("Last Report Name was: " + vReport, "", "") 
// Do Outlook stuff
}
Else
{
  @MsgBox("NO REPORT FOUND!", "", "")
}




Now that I know it works, I will be able to insert that into my real application, just need to come up with a renaming scheme now.  Want to rename ReportNameDateTime.htm into GenericName.txt vs. .htm.  But now that I know the name I should be able to use @Shell to rename it, or to add to a Zip file.  The key was knowing the name, and you have solved that.

It may still be a good idea to provide a future option to provide prompting tools at run time for path/reportname.

Thanks again Erika.....despite my constant requests for more and more, you still come through for me.
Grin
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Report Name Utilities Needed
Reply #4 - Mar 21st, 2005 at 11:22pm
Print Post Print Post  
Hello Erika.....

Finally got function to get Report Name installed in real application.

Made a number of changes to allow reports to go Outlook as an attachment or as an imbedded message.  Both are working OK right now.

Also made some changes to make it more generic for a function to use with any report and for any Report Path.   

Still doing some refining, but having the name of the report was the big obstacle.

Thanks again.....




  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged