@DoWhile looping agent problem

I’m attempting to create a view agent that does the following (on all documents selected):

  1. pull the values in multi-value field “Activity”. The field has multiple text items of the type “date - activity text” (with space,dash, space separating the pieces of text)

  2. parse the “date” portion of the text and place in value of “tmpDate” (leftmost up to space, dash, space)

  3. parse the “activity” portion of the text and place in value of “tmpAct” (rightmost after space,dash,space)

  4. create a new document of type “Mod_Activity”, which is a reponse document, inherits values from the parent (really, only the $ref is ever used…)

  5. On “Mod_Activity” form, sets value of “Activity_Date” field to “tmpDate”

  6. Sets value of “Activity_Enter” to “tmpAct”

  7. On the parent document, sets the value of “Recent_Activity” to today’s date

  8. Saves and closes the response document

  9. Goes to the next line item in the original document and starts the process again.

Here’s the agent code so far:

@If(@Elements(Activity) = 0; @Return(0); “”);

n := 1;

@DoWhile(

	tmpDate:= @left(Activity; " - ");

	tmpAct:= @Right(Activity; " - ");

	@command([Compose]; ""; "Mod_Activity");

	@SetField("Activity_date"; tmpDate);

	@SetField("Activity_enter"; tmpAct);

	@SetDocField($Ref; "recent_activity"; @Today);

	@Command([FileSave]);

	@Command([FileCloseWindow]);

	n := n + 1;

n <= @Elements(Activity);

)

I’m getting an error that I’m missing an expected function, though I have no idea why. (Shows up at the last parenthesis in the formula). I also haven’t been able to test the agent since it won’t save the formula in its current state.

If anyone can tell me if the logic/programming will fail, let me know why or a possible fix. This would be greatly appreaciated.

Thanks in advance.

Subject: There are three things that I can see in your code…

@If(@Elements(Activity) = 0; @Return(0); “”);FIELD recent_activity := @Today;

n := 1;

@DoWhile(

	tmpDate:= @Left(Activity[n]; " - ");

	tmpAct:= @Right(Activity[n]; " - ");

	@command([Compose]; ""; "Mod_Activity");

	@SetField("Activity_date"; tmpDate);

	@SetField("Activity_enter"; tmpAct);

REM { @SetDocField($Ref; “recent_activity”; @Today) You do not need this in the loop};

	@Command([FileSave]);

	@Command([FileCloseWindow]);

	n := n + 1;

REM { n <= @Elements(Activity) you do not need the trailing “;”};

n <= @Elements(Activity)

)

Subject: RE: There are three things that I can see in your code…

That works for saving the agent. Now I’m getting an error. “@Command or other UI functions not allowed with this search type.”

I’m stumped. Does this mean that an agent cannot spawn new document creation? Or am I missing something? (This agent is run on selected documents)

Subject: Ah, sorry. The view agent in @Commands can not do it…

LS Agent can.Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
While Not(doc Is Nothing)

acts = doc.Activity

If doc.acts(0) <> “” Then

For i = Lbound(acts) to Ubound(acts)
   set newDoc = db.CreateDocument
   newDoc.Form = "Mod_Activity"
   Call newDoc.MakeResponse(doc)  'If needed
   newDoc.Activity_Date = strLeft(acts(i), " - ")
   newDoc.Activity_Enter = strRight(acts(i), " - ")
   Call newDoc.Save(True, False)
Next
doc.Recent_Activity = Today
doc.Activity = ""
Call doc.Save(False, True)

End If
Set doc = collection.GetNextDocument(doc)
Wend