Search code examples
lotus-noteslotus-dominolotusscript

Set Run on Behalf of for NotesAgent


Is there a way to set "run on behalf of" in NotesAgent?

I tried solution with NotesNoteCollection

  Dim nc As NotesNoteCollection
  Set nc = db.CreateNoteCollection(False)
  Call nc.SelectAllCodeElements(True)
  nc.SelectAgents = true
  Call nc.BuildCollection

Then I loop nc and find my agent and set item $OnBehalfOf

call agentNote.replaceitemvalue("$OnBehalfOf", "username")
call agentNote.save(true, false)

That breaks on 'Save', it says it's not allowed to save agent.

I have also checked C API and have not found anything that can help me (but I could miss something)


Solution

  • First of all -as mentioned in the comment by Richard- you need Designer- Access to the database to be able to change an agent like that as you directly modify a design element instead of using the interface (that somehow circumvents this for editing agents).

    Second: Whenever you modify an agent via its underlying NotesDocument, you destroy the signature on the design- element: Even when saving works the agent will be broken and not run again.

    So you need to add an agentNote.Sign() before your agentNote.Save(...) otherwise the agent will not be able to run.

    And of course the person who executes this code needs the appropriate server right (Serverdocument - Security - Sign agents to run on behalf of someone else), otherwise the agent will not run.