javascriptlotus-dominolotusscriptdomino-designer-eclipsehcl-notes

HCL Domino 11 - Javascript - How to redirect to same document after doc submit ? - View not getting refreshed


I have a web application. After submitting the form using documents.form[0].submit(), the document closes. Instead of getting closed, I need to open the same document in edit mode. I tried to print the doc URL through WebQuerySave Agent. Below is my code in the agent but this prints the last but one doc instead of last doc since the view is not refreshed. I tried adding view.refresh but still it gets the last but one doc. How do I refresh the view and get the current saved doc URL or is there any other way to get the currently saved doc URL ?

Sub Initialize
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim doc As NotesDocument
  Dim dbview As NotesView
  Dim docUnid As string
  Set db = session.CurrentDatabase
  Set dbview = db.Getview("(WorkOrders)")
  Call dbview.Refresh()
  Set doc = dbview.Getlastdocument()
  docUnid = doc.Universalid
  Print "[https://kclisd01/nibsport.nsf/(WorkOrders)/" & docUnid & "?editDocument]"
End Sub

Solution

  • Use NotesSession.DocumentContext to get the document the agent is currently working on.

    Set doc = session.DocumentContext
    

    As described in the linked help document:

    For an agent run from a browser with @Command([RunAgent]) or @Command[ToolsRunMacro], the in-memory document is the current document. In the case of WebQueryOpen, this is the document before Domino® converts it to HTML and sends it to the browser; in the case of WebQuerySave, this is the document before Domino® saves it.