Immediately trigger backend agent

What is the best way to trigger a backend server agent (immediately) to create B (child) document when A (parent) is saved ?
In another words:

I want when document A is saved AND
If FieldOne = "TypeA" then
   Create a child document (triggered immediately after the save or doc A by a backend agent)
  Just save doc A

This app is on LN 5.0.10 and LN 5.0.10  client
Note: I have already used the functionality of ' if document has been modified and saved ' for the agent but i cannot have the system wait if there is a delay due to agents queue. I want it immediately triggered just like servlet works on web.

Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
And explain why it has to run on server.

Did you try: NotesAgent.RunOnServer(NotesDocument.DocId)

Don't put it in an agent then.  Put it in the UI events for the form!
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

navgupAuthor Commented:
Qwaletee, I don;t understand what UI event of form are you talking about ? Pl explain.

I am concerned about the security for running this agent (AG1):
For eg.
A parent document A is created by User X, who do not have access to run 'Restricted/Unrestricted' agents on the server,
Agent AG1 is signed by the administrator of the notes server.
Will UserX be able to trigger the agent (using RunOnserver) on the server?


navgupAuthor Commented:
Also, there is one more concern i have. Even if the backend agent creates the document, what is the best way to have
newly created document inherit the required fields from the parent document. How is it possible to do it more effectively in the backend on the server (just like ComposeDocument works)?

I know one way is to copy items one by one from one doc to another... which is going to be very tedious.
ZvonkoSystems architectCommented:
Did you try to make that AG1 run as scheduled agent on new and modified documents? That would be the normal aproach.
Whithin that run does the AG1 decide wether to create a response document or not and set a flag in parent document that those document is handled (in case you modify it later and do not want to have two response documents for a single parent)
The documents for NewOrModofied documents are presented as DocumentCollection.
There is always a delay when running the scheduled agents, you cannot force it to run immediately.

The security for RunOnServer is taken from Notes client usser, the caller, not the Agent signer. So if your does not have the priviledge to run unrestricted commands, then will the agent abort when trying to do so.

navgupAuthor Commented:
Well.. i don't quite understand your second paragraph. These users have access to create child document (Authors) in the database as they are normal users to the server (not a power user or admins). These users are listed in the "Run restricted LotusScript/Java agents:" on the server but they are not in "Run Unrestricted LotusScript/Java agents". Does this kind of agent (just to create a document) falls under restrcited or unrestricted category ? I thought it falls under restricted category.
ZvonkoSystems architectCommented:
If the users are allowed to create documents, then the agent will also be allowed to do so.
ZvonkoSystems architectCommented:
But that is important only if you want to run the AG1 from Notes Client on the Domino server.
The regular way is to let the AgentManager run the scheduled agent AG1.
Sjef BosmanGroupware ConsultantCommented:
Qualetee meant not to use agents at all.

Put this in the QuerySave or (better) the PostSave event:

Sub PostSave(uidoc As NotesUIDocument)
    dim doc as notesdocument
    dim db as notesdatabase
    dim childdoc as notesdocument

    set doc= uidoc.document
    set db= doc.parentdatabase
    set childdoc= new notesdocument(db)
    replaceitemvalue "Form", "form of a child document"
    replaceitemvalue ..., ... ' add other fields here
End Sub
navgupAuthor Commented:
Like i said earlier, there are too many fields to inherit and i cannot assign values to each field from the parent
Is there a better way to perform inheritance (synchronize) in the backend (not necessarily from parent to child but between just
two main documents)?
Sjef BosmanGroupware ConsultantCommented:
You "cannot assign values to each field from the parent document". Not true. Should be read as
You "don't feel like writing all the code to assign values to each field from the parent document". It's a normal thing. :)

How about the NotesDocument.CopyAllItems method? Or you can make a complete copy of the document and then modify it?
Or, if you name the "shared" fields using a conventio that can differentiate them from the other fields, you can loop and pick off teh "matching" fields with about 6 lines of code.
navgupAuthor Commented:
qwaletee: can you provide me with those 6 lines of code.. ?
I don;t understand how having shared fields is going to help me sync up the data between one form to another?
Sjef BosmanGroupware ConsultantCommented:
Use names that are alike, such as starting with a prefix that indicates sharing, e.g. in both forms name the "shared" fields like "ShrFieldname", so you can copy all fields starting with "Shr" to the other document.


Dim items as variant

Set items= doc.Items
Forall itemi in items
    If Left(,3)= "Shr" Then
    End If
End Forall

Or equivalent.
All Courses

From novice to tech pro — start learning today.