Search code examples
lotus-dominoforms

Duplicate a Domino document in a web form


I have a Lotus Domino web application that uses plain old forms. The database already has some documents, and I want to clone one of the documents. So I thought that I could just issue an URL request like this:

/database.nsf/viewName?clone=12345678

This URL should open the form and prefill all form fields with those from the document with the ID 12345678. The user should then be able to edit all fields.

  • At which point can I intercept the form creation?
  • How do I access the newly created document that stores the form values?
  • Can I do all this in LotusScript, or do I have to use the formula language?

Solution

  • Just use an agent (Trigger: None). URL would be something like: /database.nsf/YourAgentname?OpenAgent&clone=12345678

    In the agent you can get the parameter like this:

    Dim ses as New NotesSession
    Dim docParam as NotesDocument
    Dim strQueryString as String
    
    '- Get the parameter- document
    Set docParam = ses.DocumentContext
    
    '- get the querystring
    strQueryString = docParam.getitemValue( "Query_String" )(0)
    
    '- querystring will be OpenAgent&clone=12345678
    '- here you can extract the id from the querystring
    ....
    
    '- then you get the document (if 12345678 is the noteid e.g by db.GetDocumentByID( ) 
    '- or if it is your own key by NotesView.GetDocumentbyKey()
    Set docOrigin = ....
    
    '- Now create a new doc 
    Set docClone = New NotesDocument( db )
    '- Fill the fields
    Call docClone.ReplaceItemValue( "Field1" , docOrigin.GetItemValue( "Field1" ) )
    '- Or all at once
    Call docOrigin.CopyAllItems( docClone )
    
    '- Here is the trick: Redirect to the new document using the agent output:
    Print "[/" & db.HttpURL & "/_/" & docClone.Universalid & "?EditDocument" & "]"
    

    The Brackets make the browser directly redirect to that page...

    This code was just written from "memory" and might contain Typos / logical errors, but it should be a good starting point...