Agent forward forms

Hello,

I have created a scheduled simple agent to forward some forms with a specific conditions, the form is from “test” and it must have a field (state) that it contains “adjunto”. That simple agent works fine, but I have made this agent with lotusscript but it doesn´t work, and i don´t know why.

This is my scheduled code:

Option Public

Option Declare

Use “Solicitudes”

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim ns As NotesSession

Dim uidoc As NotesUIDocument

Dim ws As NotesUIWorkspace

Dim Col As NotesDocumentCollection

Dim form As NotesForm

Dim calculo As String

dim forward As NotesUIDocument

%REM

Sub Initialize

Description: Comments for Sub

%END REM

Sub Initialize

'

Set ns = New NotesSession

Set ws = New NotesUIWorkspace

Set uidoc = ws.Currentdocument

Set db = ns.Currentdatabase

Set form = db.Getform("TestDevelop")

'

On Error resume Next

'

Dim dateobj As New NotesDateTime("")

'

'@Adjust( fecha-hora ; años ; meses ; días ; horas ; minutos ; segundos ; [ DST ] )

'

calculo = "(@Adjust(FechaSolicitud; 0; 0; 0; 0; 0; 0)<= @Today) & (Form = ""TestDevelop"") & (Estado = ""Adjunto"") " 

'

Print "hay " + CStr(col.count) + "documentos"

Set col = db.Search(calculo, Nothing, 0)

'

If col.Count > 0 Then

	Set doc = col.Getfirstdocument

	While doc Is Nothing

		Call uidoc.Forward

		'

		Set forward = ws.CurrentDocument

		Set doc = forward.Document

		'

		Call forward.FieldSetText( "EnterSendTo", "an email")

		Call forward.FieldSetText( "Subject", "a string")

Call forward.Send

		'

		Set doc = col.GetNextDocument(doc)

	Wend

Else 

	Print "No hay documentos"	

End If

End Sub

Any suggets?

Subject: RE: Agent forward forms

First of all, I would remove the “on error resume next” - at least while you are testing. This is preventing you from seeing where the script breaks.

You are using “Call uidoc.Forward”, which will take the current uidocument and put it into a new email, which the user can then interact with and send. But then you apparently want to set those fields and send it yourself, so you didn’t need a uidoc…so then you try to get the document form of the unsaved uidoc. So what you’ve written is:

Call uidoc.Forward

Set forward = ws.CurrentDocument

Set doc = forward.Document

Call forward.FieldSetText( “EnterSendTo”, “an email”)

Call forward.FieldSetText( “Subject”, “a string”)

Call forward.Send

But since you are writing to and sending the doc, not the uidoc, you don’t even need to do a uidoc.forward. Off the top of my head:

set olddoc = uidoc.document

set fwddoc = new notesdocument (db)

call olddoc.CopyAllItems(fwddoc,True)

Call fwddoc.FieldSetText( “EnterSendTo”, “an email”)

Call fwddoc.FieldSetText( “Subject”, “a string”)

Call fwddoc.Send

Subject: Also …

… you’re not putting an eval around your @adjust strings, so you are actually searching for that “@adjust(…” text