Question

I'm having trouble passing a param from a SSJS action to a LS backend agent. In the SSJS i have this code:

var doc:NotesDocument = database.createDocument();
doc.appendItemValue("DeleteDocs",arr);
doc.appendItemValue("Form","frmWFSDeleteDocs");
var UNID = doc.getUniversalID();
dBar.info(UNID, "Doc ID");
doc.appendItemValue("ParentID",UNID);
doc.save();
var agent:NotesAgent = database.getAgent("WFSDeleteDocs");
dBar.info(doc.getItemValueString("ParentID"));
agent.runOnServer(doc.getItemValueString("ParentID"))

The UNID that is displayed in the dBar info is the correct document UNID. In my LS agent I have this code:

Set agent = s.CurrentAgent    
NoteId = agent.ParameterDocID 
Print "Notes Param " + NoteID
Set thisDoc = db.Getdocumentbyunid(NoteId)

In the log the NoteID is not the UNID but HTTP Server: Agent printing: Notes Param 5A3439

and of course the getDocumentbyunid fails. My understand looking at the help is that this should be the same value as I insert as the param in the runOnserver. Am I missing something

Was it helpful?

Solution

You need to run the agent using agent.run(<note id>). This will transfer the note id to the agent and you can then read the note id using agent.getParameterDocID().

So, in your case do this in SSJS:

var agent:NotesAgent = database.getAgent("WFSDeleteDocs");
agent.run(doc.getItemValueString("ParentID"))

Update: If you want to run the agent as signer, use sessionAsSigner:

var backendDb:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), database.getFilePath());
var agent:NotesAgent = backendDb.getAgent("WFSDeleteDocs");
agent.run(doc.getItemValueString("ParentID"))

OTHER TIPS

You are mixing NoteID and UniversalID

UniversalIDs are universal across different replicas of databases, often even globally universal like UUIDs or GUIDs

NoteIDs are local to a Notes-database. The same document in different replicas of a database has usually different NoteIDs assigned to the same document.

Agent parameter passing MUST be a NoteID. There is no other option at all.

I don't know the SSJS Notes/Domino-API, but you should be able to use something like this:

agent.runOnServer(doc.getNoteID())

So your SSJS code would be

var doc:NotesDocument = database.createDocument();
doc.appendItemValue("DeleteDocs",arr);
doc.appendItemValue("Form","frmWFSDeleteDocs");
doc.save();
var agent:NotesAgent = database.getAgent("WFSDeleteDocs");
agent.runOnServer(doc.getNoteID())

And your Notes-agent-code should use

Set thisDoc = db.GetdocumentbyId(NoteId)

instead of

Set thisDoc = db.Getdocumentbyunid(NoteId)

Your complete Notes-agent

Set agent = s.CurrentAgent    
NoteId = agent.ParameterDocID 
Print "Notes Param " + NoteID
Set thisDoc = db.GetdocumentbyId(NoteId)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top