?
Solved

need to count +1 (add a new document and set the new number)

Posted on 2005-04-21
2
Medium Priority
?
269 Views
Last Modified: 2013-12-18
hi,

i have a view where all documents are sorted descending.
the filed "number" is a text filed.
in the view it's displayed as "text to number".

i need a script that if a button is pressed
- the view "list" is found
- the 1st number (in the 1st column) is the highest available number is
- a new document is created and the value of the field number is the actual highest number +1
  (if needed i can change the view but not the filed properties.)

it'd be very good if pressing this button the new documents is presented in edit mode to the user that he can enter the equivalent name for this number in the field name.

0
Comment
Question by:hreinart
  • 2
2 Comments
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 13832660
In your script define the following function to retrieve the new number :

Function NextNumber As Long
   Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim lu As NotesView
   Dim doc As NotesDocument

   Set db = session.CurrentDatabase
   Set lu = db.GetView("list")
   Set doc = lu.GetFirstDocument
   REM SequenceNumber is the field that holds the number of the document
   NextNumber = Clng(doc.SequenceNumber(0)) + 1
End Function

Now to create/open the document :

REM DEFINE VARIABLES
Dim session as New NotesSession
Dim db as NotesDatabase
Dim docNew as NotesDocument

REM CREATE THE NEW DOCUMENT
Set docNew = db.CreateDocument
docNew.Form = "NameOfYourForm" 'assign form
docNew.SequenceNumber = Cstr(NextNumber) 'get new number from the function NextNumber, declared above
Call docNew.Save(True, True) 'save the document

REM OPEN DOCUMENT
REM --- BROWSER ---
Print "[/" & db.FilePath & "/0/" & doc.UniversalID & "?EditDocument]"

REM --- NOTES CLIENT ---
Dim ws As NotesUIWorkspace
Call ws.EditDocument(True, docNew) 'open document in edit mode in the notes client
0
 
LVL 8

Accepted Solution

by:
Jean Marie Geeraerts earned 400 total points
ID: 13856555
Here's another maybe better solution :
1. In your document define a sequenceNumber field that is computed, formula the same as the field name
2. Define a WebQuerySave-agent (e.g. "wqsSequenceNumber")
3. Compute the number in the WebQuerySave-agent.

To not confuse the user, I usually display a message for new documents and the number for existing documents. I use the hide when formula's !@IsNewdoc and @IsNewDoc to toggel which of the two is displayed. So,

number:
<this number will be computed when you save the document> hide-when: !@IsNewDoc
[SequenceNumber] hide-when: @IsNewDoc

In WebQuerySave event:
@Command([ToolsRunMacro]; "wqsSequenceNumber");

The agent "wqsSequenceNumber" has the following code :
Sub Initialize
      REM ==================================================================================
      REM DECLARE VARIABLES
      REM ==================================================================================
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim lu As NotesView
      Dim docNumber As NotesDocument
      Dim doc As NotesDocument
      Dim lngNumber As Long
      
      REM ==================================================================================
      REM GET REFERENCE TO THE CURRENT DOCUMENT
      REM ==================================================================================
      Set doc = session.DocumentContext
      If Not doc.IsNewNote Then Exit Sub 'only run the agent on new documents
      
      REM ==================================================================================
      REM LOOKUP THE FIRST DOCUMENT IN THE NUMBERED LIST
      REM The view "list" is sorted descending on the sequence number
      REM ==================================================================================
      Set db = session.CurrentDatabase
      Set lu = db.GetView("list")
      Set docNumber = lu.GetFirstDocument
      'if no document in the view, use the first number, otherwise increment with 1
      If docNumber Is Nothing Then
            lngNumber = 1
      Else
            lngNumber = Clng(docNumber.SequenceNumber(0)) + 1
      End If
      doc.SequenceNumber = lngNumber 'the field containing the sequence number is called 'SequenceNumber'
      'save changes made to the document
      Call doc.Save(True, True)
      
End Sub

All you need to do now is use the formula
@Command([Compose]; "frmNumbered")
to create a new document and the new number will be used once you save the document.
("frmNumbered" is the name or alias of the form you use.)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question