Search code examples
formulalotus

Lotus notes Formula. trying to run an @command inside of a fields validation


I am trying to use formula to open a document from within a field when it comes to validation. Basically i have set up a database that checks for duplicate entries and I want the database to (if a form is created) check that it doesn't already exist and if it does ask the user if it wants to open the form. I have got it all set up and acquired the UNID but when I come to save the document to test (with everything working perfectly) it gives the following error

@commands and other UI functions are not allowed in this context

Not sure what to try. Any help would be appreciate. The command I used is as follows

@Command([EditDocument];1;Unid) //where Unid is an ID I have acquired previously

Solution

  • This is a task, that cannot be done with formula language. As the message sais: @Commands cannot be used in any of the contexts that could help you with this task.

    You need to use LotusScript in any matching event (e.g. QuerySave) to do this Check and open the other document. Here is some example code:

    %include "lsconst.lss"
    Sub QuerySave( Source as NotesUIDocument, Continue as Variant )
      Dim ses as New NotesSession
      Dim db as NotesDatabase
      Dim ws as New NotesUIWorkspace
      Dim doc as NotesDocument
      Dim ok as Variant
      Dim strOtherUnid as String
      Set db = ses.CurrentDatabase
      strOtherUnid = Source.Document.OtherUnid(0)
      If strOtherUnid  <> "" then
        Continue = False
        ok = Messagebox ("There is already another document, do you want to edit it?" , MB_YESNO + MB_ICONQUESTION, "QUESTION" )
        if ok = IDYES then
          Set doc = db.GetDocumentByUNID( strOtherUnid )
          Call ws.EditDocument( False, doc )
        End if
      End if
    End Sub
    

    This code is not tested at all, just to be used as a starting point. It needs a field called "OtherUnid" that contains the universalid of the other document.