Attempting to send email

I was assigned the task of “automating” a workflow process.

The application that I created starts by allowing a user to fill in the information about the process then click a “Submit” button. The button attempts to save the document, causing the validation process to begin. As the document fields validate, signature and date fields get filled in. The last step of the validation checks to make sure that the user chose to “Submit” or just “Save”. The option to submit will then send an email using the trusty old @MailSend(…). The email notifies the next user in the process that it is their turn to click their button.

All the rest of the users have the option to “Approve” or “Reject” their step in the process. The logic is the same. If the user approves the process then after validation (and figuring out who the next user is) the email is sent. Rejecting sends the email to the previous user. Again, all of this is using @MailSend(…).

The whole process was working great until someone pointed out that the emails were coming from the user that is clicking the button and they would like it to come from something more official (like the server). Unfortunately, changing the “from” or “principal” is not an option when assigning the parameters in @MailSend. (ie. If I want to use [INCLUDEDOCLINK]).

After hours of exercising my Google skills, I proceeded to create an agent (using lotusscript) to send the email. Several more hours of trying to get it to work, I am stumped.

Currently, I want the button to validate all the fields and save the document. After everything validates, I want the email to be sent to the appropriate people. Finally, the document needs to close without prompting the user to save the document again.

I know I’m asking for a lot, but I could use some expert help.

The code I’m using for the button is:

@If (@Command([FileSave]);

 @Do (

      @Command([ToolsRunMacro]; "SendMail");

      @Command([CloseWindow])

 );

 @StatusBar("Save Unsuccessful")

)


It appears to be calling the agent after the document is closed. The first several lines of the agent are:

Dim workspace As New NotesUIWorkspace

Dim uiDoc As New NotesUIDocument

Dim document As NotesDocument

Dim … Some more variables …

Set uiDoc = workspace.Currentdocument

Set document = uiDoc.Document


The error is occurring at the last line because uiDoc is not being set to the current document. Running the debugger shows that there is no current document assigned to workspace.

Any help with this would be greatly appreciated.

Subject: Use the help file

In the help for @command([ToolsRunMacro]) is the following, which should help…

This command executes after all @functions. Use @Command([RunAgent]) to execute immediately. See the Order of evaluation for formula statements topic for more details.

Subject: Thanks for the response.

I’ve become quite familiar with the help file.

I’ll save you a long story, but I tried the RUNAGENT but it caused a whole different set of errors.

I re-thought the process and decided to create an agent that ran after a document is created or modified. That agent picks up any documents flagged as needing notification or reminders to be sent and processes the emails. I’ve also got an agent that runs every morning that will trigger the same agent in case something got missed.

Thanks again for the response, but I’ve got it working now.

Subject: documentcontext?

The other thing to try is to use the documentcontext in the agent, rather than uidoc.

Also, why is the button in formula and not lotusscript? Then you can control when it runs without a problem (you might want to look at parameterdocid as well if you try this). Or move the agent code into a script library and just call it straight from the button without using an agent at all