371 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Forum | Blogs | Search | myPL | About 
 
May 24, 2012, 12:45:29 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Calendar Login Register  
Pages: [1]
  Print  
Author Topic: How to Write Code that Auto Generate A Serial Number  (Read 3351 times)
0 Members and 2 Guests are viewing this topic.
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« on: April 07, 2010, 12:29:10 AM »

Hi All,
I'm new to Lotus environment. I really need to get a help in finding a code for Generating A Serial Number (Auto).
For example OFDR-20100407-001.
Red = Form Name
Purple = Year
Orange = Month
Green = Day
Blue = Form Number
Logged
TexasSwede
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #1 on: April 07, 2010, 11:08:19 AM »

Explain a little more what you are looking for. Where is the code supposed to run?
What is "form name" and "form number" coming from?
Does the serial numbers have to be unique?
For the date part, I would use Format$(now(),"yyyymmdd").
For the "form number", do you want them to be sequential, or start over for each "form name"?
You probably need to store the last used number in a profile document. Is the code going to be used on multiple replicas, or is it just executing in one replica on one server?

Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #2 on: April 08, 2010, 02:18:28 AM »

I'm sorry for the bad explanation  Wink
For the form name, I just hard-coded it. Because the application that I was about to developed only have one type of form(that is the registration form). But for the form number, it will increase everytime a person submit the registration form that they had filled in. The form name that I had hard-coded will then be concatenate with the date that the form was created/submitted then concatenate with the form number.
Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #3 on: April 08, 2010, 02:34:35 AM »

I'm sorry if my explanation is a bit hard for you to understand. I've come up with one example that is used to auto-generate serial no/reference no. But the coding was in LotusScript and it is hard to understand. The example declared the CreateRefNo action on the Global section then it links to other documents(forms,views,etc). I really appreciate if someone can come up with a solution that uses formula instead of LotusScript. Thank you...
Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #4 on: April 08, 2010, 03:26:01 AM »

I don't really understand on the "profile document" that you mentioned. And the code is going to execute in one replica on one server.

Logged
TexasSwede
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #5 on: April 08, 2010, 02:29:43 PM »

I'm sorry if my explanation is a bit hard for you to understand. I've come up with one example that is used to auto-generate serial no/reference no. But the coding was in LotusScript and it is hard to understand. The example declared the CreateRefNo action on the Global section then it links to other documents(forms,views,etc). I really appreciate if someone can come up with a solution that uses formula instead of LotusScript. Thank you...

I think a formula solution would be very complicated. Lotusscript is not very hard, and you should learn it anyway.
Profile documents are described in the online help. Those are documents you use to store information, either for all users or per user. So I would create a profile document (call it "profileCounter", for example) with two fields:
CounterValue - last sequence number used (your "form number")
CounterDate - The date the counter value was last updated, so you can start over each day if you want.


Dim session ans New NotesSession
Dim profiledoc as NotesDocument
Dim lastcnt as Integer
Dim lastdate as String
dim serial as string
dim formname as string

' *** Get profile document and values
Set profiledoc = session.CurrentDatabase.GetProfileDocument("profileCounter")
lastcnt = Cint(profiledoc.GetItemValue("CounterValue")(0))
lastdate = Cdat(profiledoc.GetItemValue("CounterDate")(0))
' *** Was counter last updated a previous/other day?
if lastdate<>Cdat(Today()) then
  lastcnt = 0   ' Set last counter to zero
end if
lastcnt = lastcnt + 1   ' Increase counter by one
' *** Write values back to profile document
call profiledoc.ReplaceItemValue("CounterValue",Cstr(lastcnt))
call profiledoc.ReplaceItemValue("CounterDate",format$(today(),"mm/dd/yyyy"))
call profiledoc.Save(true,False)
' *** Now we have the "form number", and can generate the serial number in desired format
formname = "OFDR"
serial = formname & "-" & Format$(today(),"yyyymmdd") & "-" & format$(lastcnt,"000")


Does not have to be very complicated.
Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #6 on: April 08, 2010, 07:25:42 PM »

Thank you so much Grin... I will find information regarding the profile documents and use LotusScript as you suggested. As for the part of updating the counter, maybe I don't want to start over on each day, but each year. So what part should I change?
I'm taking baby steps in learning Lotus Designer and I only started about a month ago, so I really appreciate your effort in explaining the solution for me...
« Last Edit: April 08, 2010, 07:30:29 PM by nur_afini » Logged
TexasSwede
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #7 on: April 09, 2010, 08:13:48 AM »

Should be enough to change one line, in order to start over once a year. Are you sure you will not excede 999 numbers per form?

Just change If lastdate<>Cdat(Today()) Then to check the year instead of the exact date:
If Year(lastdate)<>Year(Cdat(Today())) Then


Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #8 on: April 12, 2010, 12:54:06 AM »

Oooo, I didn't know there are limitations. Then maybe I should start over for every month. So the code should look something like this (Can you please correct me if I'm wrong):

If Month(lastdate)<>Month(Cdat(Today())) Then
lastcnt = 0 
end if
lastcnt = lastcnt + 1


Anyway, thank you very much for your kindness in helping me  Grin
Logged
TexasSwede
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #9 on: April 12, 2010, 01:31:54 PM »

You are the one that specified the limitation, by specifying a 3-digit form number. 3 digits can only give you a number up to 999.
You can make it 4 digits or 5 digits (up to a value of 32635) by modifying the Format$ statement. If you want to go above 32635, you need to change the data type of lastcnt to Long and modify the conversions to convert the value in the profile document to Long instead of Integer.

Logged
nur_afini
Newbie
*
Offline Offline

Posts: 11


View Profile
« Reply #10 on: April 12, 2010, 07:30:34 PM »

Ooo, I see about that. Maybe I had a little bit misunderstanding yesterday. But I understand it know after I've read your reply post...
Logged
gayathri viswanathan
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #11 on: December 23, 2010, 03:57:08 AM »

TexasSwede has given you good code.

Here are the steps to follow:
a) Create a profile document to hold the serial number (look up profile documents on help to see what they are).
b) Write an agent (easiest in LotusScript) to pick the profile document, do the calculation for your serial number (you can have alpha-numeric and computed values) and set your field
c) Call the agent from where you need serial number generation.

Couple of things to note: If your application is going to run on multiple servers, you need to choose which one would be the server where the serial number generation runs.
Also if your users will replicate the application locally, you may want to ensure that the serial number generation runs only on the server (after they replicate back). This will ensure that you dont have duplicates.
Logged
trevlaws
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #12 on: December 25, 2010, 07:42:06 PM »

Andre Guirard wrote the definitive wiki article on this subject here:

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/sequential-numbering.htm

Strongly recommended!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!