BO 5.1.8 VBA Scripts and Task Scheduler

Hello all,

I have recently been testing Business Objects 5.1.8 for my work and trying to see if we can still use our old method of Automation that we used with 4.1.5. In the past we scheduled jobs through Windows Task Scheduler that kicked off business objects with a line similar to this:

The scripts were located in the Scripts directory, along with matching .sbx files (I’m not sure what these are, but they aren’t text that’s for sure). I wanted to give one of these scripts a try with 5.1.8. The script in particular that I tried was an e-mail script. I ensured that the script worked with Broadcast Agent (we are having reliability issues with BCA so we would like to get the Windows Task Scheduler working with 5.1.8 instead). The script doesn’t appear to do anything when I schedule it through task scheduler, it just sits there the entire time until its window is gone, and it shouldn’t take more than 10-15 seconds to run. The line that I have in the new scheduler looks like this:

But I have tried without the -nologo, without the -blind, I’ve tried having the .spt included at the end of the script name. I have tried opening the report (which works from command line, but the script doesn’t run so there isn’t much point in that). I have made sure that no prompts for passwords or wizards or macros are coming up when I start busobj.exe from command line with these options as well.

Here is the script that I am trying to run (some things have been removed for privacy :P, and this isn’t my script, I am pretty new to VBScript so there could be some pretty obvious errors in it and me not know it.

Dim appint
Dim vars
Dim objDoc
Dim objRpt
Dim i As Integer
Dim strFile As String
Dim objMail As Object
 
Sub main()
 Set appint = CreateObject("BusinessObjects.Application")
 appint.Interactive = False
 Set vars = appint.Variables
 
 strReportName = "DatabaseCodeChangeAuto"
 
 Set objDoc = appint.Documents.Open(strReportName)
 objDoc.Refresh

 Set objMail = CreateObject("Persits.MailSender")
 objMail.ResetAll

 'Build the email
 objMail.Host = "smtpserveraddress.somewhere.com"
 objMail.From = "person1@somewhere.com"
 objMail.Subject = "Business Objects: " & strReportName
 objMail.Body = "Database Code Changes Report is attached"
 objMail.IsHTML = True
 objMail.AddAddress ("person1@somewhere.com")
 objMail.AddAddress ("person2@somewhere.com")
   
 For i = 1 To objDoc.Reports.Count
   strFile = "c:\temp\" & strReportName & "_" & i & ".rtf"
   Set objRpt = objDoc.Reports.Item(i)
   objRpt.ExportAsRtf (strFile)

   'Add Attachments
   objMail.AddAttachment strFile

   
 Next i
 objDoc.Close

 'Send Email
 objMail.Send
 objMail.ResetAll

 Set objMail = Nothing

 Application.Exit
End Sub

The Persits mail sender is installed and functioning, I have verified that it worked with BCA.

So, does anyone have any ideas as to what I am doing wrong, or if what I am trying to do is even possible with this version of Business Objects? :slight_smile:

Thanks for your help!

Toby


Tobyus (BOB member since 2005-09-22)

The command line does not have a -script parameter. I can only assume that was removed in v5 when the old scripting language was replaced by VBA. Put your code in the document itself in the AfterRefresh event. You also won’t need the appint or document open stuff, since that’s already “there” by definition.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Thank you so much! I will give that a shot now. :slight_smile:

I just have one question before I make changes to the code. How do I refer to the open document to tell it to export to an rtf?

For example, right now I am setting up the objDoc equal to the document and opening it in one line, then telling objDoc to export to an RTF. Will objDoc already be defined now that the document is already open? Or should I just leave that step as is?

Thanks again :slight_smile:


Tobyus (BOB member since 2005-09-22)

ThisDocument is used for a document to reference itself. You can either use ThisDocument directly, or set objDoc = ThisDocument.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Thanks again, that’s what I needed to know :slight_smile:

I am going at this from 2 different ways now. I am going to try one vbs that is called by Task Scheduler and from that vbs open Business Objects and the Document, refresh the document and export it to PDF then e-mail it.

The other way I’m going to try it is the way that you have been helping me with. I got the first method to work yesterday once, but it did give me an error when it got to the line:

 Application.Exit 

I tried changing that to appint.Exit and got a different error (I can’t remember what the error was now). Is there a proper way to tell Business Objects to close from a vbs?

I’ve tried:

Application.Exit

appint.Exit

Set appint = Nothing

And none of them has successfully closed Business Objects after the script completes.

Edit:


I had to do appint.Quit :slight_smile:


Tobyus (BOB member since 2005-09-22)

Yep, that’s the correct method.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)