Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

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)
Else
  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.

0
navgup
Asked:
navgup
  • 5
  • 5
  • 3
  • +1
1 Solution
 
qwaleteeCommented:
Don't put it in an agent then.  Put it in the UI events for the form!
0
 
ZvonkoSystems architectCommented:
And explain why it has to run on server.

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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Zvonko:
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?

Thanks

0
 
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.
0
 
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 user.id does not have the priviledge to run unrestricted commands, then will the agent abort when trying to do so.

0
 
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.
0
 
ZvonkoSystems architectCommented:
If the users are allowed to create documents, then the agent will also be allowed to do so.
0
 
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.
0
 
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
    childdoc.makeresponse(doc)
    childdoc.save(true,false)
End Sub
0
 
navgupAuthor Commented:
Like i said earlier, there are too many fields to inherit and i cannot assign values to each field from the parent
document.
Is there a better way to perform inheritance (synchronize) in the backend (not necessarily from parent to child but between just
two main documents)?
0
 
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?
0
 
qwaleteeCommented:
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.
0
 
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?
0
 
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.

Basically:

Dim items as variant

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

Or equivalent.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now