Computed Field Values

I am creating a form in which I want to add a field that will contain an incrementing number each time a document is created from that form (ex an invoice no) I have written a short Lotus Script to open a file, retrieve the stored number, increment it by one and then write it to the file. But I have not yet been successful in getting the script to run when a document is created and automatically put the number into the required field.  How can I best do this?
Chris_mAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
PaebdbConnect With a Mentor Commented:
Chris,
the problem with your solution (besides the fact that it is not the fastest) is how do you handle if more than one person are accessing the database and creating documents ?

I suggest you take a look at this article, it explains very good several solutions to your question.
           http://support.lotus.com/note_arch.nsf/ccb088a1de6aac738525631c0067846b/8525660500544ea685256681005c8444?OpenDocument
0
 
tuancdCommented:
Can you send me your script ?
0
 
Chris_mAuthor Commented:
I had thought that they would all have to access the same .dat file to get the incrementing no; howver, I acknowledge that if people were working on different servers, that would create a problem.  What I want to do is create a unique ID based on 4 document fields.  The ID would look like
aaaa.bbb.cccc.ddd where aaaa would be the incremental number and bbb ccc ddd being generated from alias' in keyword selection boxes.  I will read the document you suggest and see if there is anything there that will help me with the incrementing number. In the meantime, thanks for your input.

For tuancd: the script is simple, it just opens a binary file, reads the number, increments it by 1 then writes to the file the new number and closes the file.  It operates for test purposes from a button script
Sub Click(Source As Button)
 script here
end Sub                        
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
PaebdbCommented:
It is also a problem if people are working on the same server on the same database. What happens if 2 persons access the .dat file at about the same moment, generate the next number and save it back ? You will have two docs with the same incremented number.
Its the reason why read-write locks in databases and semaphores in operating systems exist.
0
 
bmc70Commented:
Here is a numbering scheme I wrote using formulas to create a tracking number. (99-000001)  It combines the last 2 digits of the year and an incremental number, using a profile doc.  The incremental number is initially set to 1,000,000 to get the desired number of leading zeros.

There is a small chance this could dupe numbers, but it is not a major concern for my purposes.


Temp := @GetProfileField("Number Profile";"Counter");
Temp4 := @Text(Temp);
@SetProfileField("Number Profile";"Counter";Temp+1);
Temp2 := @Text( @Year(@Now));
Temp3 := "-";
@Middle(Temp2;2;2) + Temp3 +  @Right(Temp4;6)
0
 
Chris_mAuthor Commented:
Thanks everybody!  I still think I would like to know how to get a script to open up a data file and copy the contents to a field when the document is saved.
0
 
PaebdbCommented:
Here the example of the open file statement help in LotusScript:

' In this example, LotusScript reads the contents of a
' comma-delimited ASCII file (c:\123w\work\thenames.txt)
' into an array of RecType. RecType is a user-defined data type.
' c:\123w\work\thenames.txt consists of the following:
' "Maria Jones", 12345
' "Roman Minsky", 23456
' "Joe Smith", 34567
' "Sal Piccio", 91234

Type RecType
   empId As Double
   employee As String
End Type      
Dim arrayOfRecs() As RecType
' A dynamic array that will get sized to
' the number of lines in c:\123w\work\thenames.txt
Dim txt As String
Dim fileNum As Integer
Dim counter As Integer
Dim countRec As Integer
' Get an unused file number so LotusScript can open a file.
fileNum% = FreeFile()
counter% = 0
Open "c:\123w\work\thenames.txt" For Input As fileNum%
Do While Not EOF(fileNum%)
   ' Read each line of the file.
   Line Input #fileNum%, txt$
   ' Increment the line count.
   counter% = counter% + 1
Loop
' Return the file pointer to the beginning of the file.
Seek fileNum%, 1
' The file has counter number of lines in it, so arrayOfRecs()
' is defined with that number of elements.
ReDim arrayOfRecs(1 To counter%)
' Read the contents of the file into arrayOfRecs.
For countRec% = 1 To counter%
   Input #fileNum%, arrayOfRecs(countRec%).employee$, _
      arrayOfRecs(countRec%).empId#
Next
Close fileNum%
Print arrayOfRecs(2).employee$ & " " arrayOfRecs(2).empId#
' Output:
' Roman Minsky 23456
0
All Courses

From novice to tech pro — start learning today.