Hi all, for your info first, i’m a newbie in domino designer.
i want to have implement a serial number on my form which auto increases for every new form opened/created. Eg. AA01, AA02, AA03 so on… how do i do this? i don’t know lotusscript
Hi all, for your info first, i’m a newbie in domino designer.
i want to have implement a serial number on my form which auto increases for every new form opened/created. Eg. AA01, AA02, AA03 so on… how do i do this? i don’t know lotusscript
Subject: auto generate serial number for form
you would have to be able to read the last issued number from some place in your database:
1/ create a profile-document that keeps your last issued number, and that will be updated every time you create a new document.
2/ in the query-save event of the document:
a/check if the document already has a serial number. If not b/retrieve the last issued number (something like @DbLookup(“”:“NoCache”;“”; “(System/Profiles)”;“LastNumber”;“LastNum”)) > raise the number by 1.
3/ Save the profiledocument with the new issued number.
Mind that this solution will not work when your database has more replica’s on different servers …
Subject: auto generate serial number for form
If you can cope with hexidecimal then why not use the noteID property of the notesdocument then you have to do no coding at all… Again, doesn’t work across replicas - you would have to use the unid for that.
Generating unique serial numbers is actually more difficult than you think - e.g. your serial number would have to be generated when the document saves rather than opens to ensure that no two are the same. If you then go for multiple replicas, it then becomes a total nightmare. If you are lazy (like me) then i go for the universal ID which is unique in all circumstances.
Cheers
Adam.
Subject: auto generate serial number for form
Jason, I suggest that you do a forum search for sequential and number. This topic has been discussed many times in this forum, and also in the ND 4 and 5 forum, and the info found in the search results will help guide you to the best solution.
Subject: auto generate serial number for form
hi lewit very simple
read carefully
okie
create one master document let it be number form
in that u create fields
of your for mat like
first field is nu keep it as editable
second field is format in that keep computed
value is aa
then you keep these two fields in one field
mean third field is
let it be format name
in that concat htese two fields
create one document based on this form
save it
then u create one view
first column values as some name"request id"
sort that column
then go to you main form
retrive that format field value into your form field
let that field is reqid
write code for this action
after saving your form increment that value of request form
any queries mail me on reddylotus@gmail.com
Subject: auto generate serial number for form
There are two methods that I use. We do a lookup from a client database for part of the reference number. You’ll need to create some views and forms for this.
Sub Postopen(Source As Notesuidocument)
On Error Goto catchError
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim countDb As NotesDatabase
Dim crntDb As NotesDatabase
Dim uiDoc As NotesUIDocument
Dim countDoc As NotesDocument
Dim countView As NotesView
Dim refNo As String
Dim cliDb As NotesDatabase
Dim cliVw As NotesView
Dim cliDoc As NotesDocument
Dim cliNameList As Variant
Dim cliName As String
Set crntDb = s.currentDatabase
countServerName = "your server name"
countDbName = "your count server name"
Set countDb = New NotesDatabase(countServerName, countDbName)
Stop
'picks up the current server
crntServer = crntDb.Server
cliDbName="your client database"
Set cliDb = New NotesDatabase(crntServer, cliDbName)
Set cliVw = cliDb.GetView("ClientList")
Set uiDoc = ws.CurrentDocument
If uiDoc.IsNewDoc Then
Set countView = countDb.GetView("LookupDocCount")
Set countDoc = countView.GetFirstDocument
insCount = countDoc.Count(0)+1
countDoc.Count = insCount
Call countDoc.Save( True, True )
cliNameList = ws.PickListStrings( PICKLIST_CUSTOM, False, crntServer, cliDbName, "ClientList", "Please Select a Client", "Please select the Client you require", 1)
Forall c In cliNameList
cliName = c
End Forall
Print cliName
Set cliDoc = cliVw.GetDocumentByKey(cliName)
Stop
cliRef = cliDoc.cliCode(0)
referenceNo = cliRef + "/" + Cstr(insCount)
Call uiDoc.FieldSetText("cliName", cliName)
Call uiDoc.FieldSetText("cliAddress1", cliDoc.OfficeStreetAddress(0))
Call uiDoc.FieldSetText("cliTown", cliDoc.OfficeCity(0))
Call uiDoc.FieldSetText("cliPostcode", cliDoc.OfficeZip(0))
Call uiDoc.FieldSetText("cliDXAddress", cliDoc.officeDX(0))
Call uiDoc.FieldSetText("cliRef", cliRef)
Call uiDoc.FieldSetText("referenceNo", referenceNo)
Call uiDoc.Save
End If
If uiDoc.EditMode = True Then
Call uiDoc.Save
End If
If uiDoc.FieldGetText("feesSet") = "No" Then
Call SetFees
End If
%REM
FIELD cliName := cliName;
FIELD cliRef:= cliRef;
FIELD referenceNo:= referenceNo;
@If(@IsNewDoc;
@Do(
database := @Subset(@DbName; -1);
server := @Name([CN]; @Subset(@DbName; 1));
cliDb:="your client database";
cliName:= @PickList( [Custom] : [Single] ; server: cliDb ; "People"; "Please Select a Client" ; "Please select the Client you require" ; 1 );
cliRef := @DbLookup("Notes"; server : cliDb; "People"; cliName; "cliCode");
referenceNo:= @Text(cliRef) +
"/"+
@Text(
@SetDocField(
@Text(
@DbLookup( "" : "NoCache" ; "" : "" ; "LookupDocCount" ; "99"; 2 )
) ;
"Count";
@GetDocField(
@DbLookup( "" : "NoCache" ; "" : "" ; "LookupDocCount" ; "99"; 2 );
"Count"
)+1
)
);
@Do(
@SetField("cliName"; cliName);
@SetField("cliRef"; cliRef);
@SetField("referenceNo"; referenceNo)
)
);
@Success
);
@If(
feesSet = "No";
@Command([ToolsRunMacro]; "Set Fees");
@Success
)
%END REM
catchErrorResume:
Exit Sub
'Error capturing in case of an error
catchError:
Msgbox "frmIns PostOpen. Error at line " & Erl()
Msgbox "Error" & Str(Err) & ": " & Error$
Resume catchErrorResume
End Sub
Subject: auto generate serial number for form
I should also say that it is much better to build this into the workflow so that the Domino server assigns the serial number in an ordered queue rather than causing the users to add the serial number. This saves the hassle of any duplicate numbers or errors with working of multiple replicas.
We’ve been using the user based method for eight years and I really wish we’d gone a different route while we were still a tiny form. It’s a problem now that we are using servers in a cluster and across multiple sites which requires a change to the workflow. If we’d got it right first of all we wouldn’t have to rewrite anything.
This is an agent that runs to allocate an invoice number (among other things)
Sub Initialize
On Error Goto ErrorHandling
' this agent use the DominoPDF dll to create a .pdf of the frmInvoice form
' this is emailed to the user address in the Response field 'SendInvoiceTo'
' a blind copy is emailed to the address in the Response field 'SendInvoiceBlindCopyTo'
' a copy of the Invoice PDF is saved within a frmReportRecord doc
' the invoice document is deleted
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim dc As NotesDocumentCollection
Dim keywordview As Notesview
Dim agent As NotesAgent
Dim doc As NotesDocument
Dim deldoc As NotesDocument
Dim sendtokeyworddoc As NotesDocument
Dim blindcopytokeyworddoc As NotesDocument
Dim urlkeyworddoc As NotesDocument
Dim insdoc As NotesDocument
Dim item As Notesitem
Dim rtItem As NotesRichTextItem
Dim url As String
Dim filename As String
Dim responsesview As String
Dim directory As String
Dim urlkeyword As String
Dim subject As String
Dim message As String
Dim countDb As NotesDatabase
Dim countView As NotesView
Dim countDoc As NotesDocument
Set session = New NotesSession
Set db = session.CurrentDatabase
Set agent = session.CurrentAgent
Set countView = db.GetView("LookupDocCount")
Set countDoc = countView.GetDocumentByKey("InvoiceCount")
Set view = db.GetView( "lookupinvoices" )
Set dc = view.GetAllDocumentsByKey( "pending", True )
directory = Strleft( db.FilePath, "\" & db.FileName )
Print dc.count
If dc.Count > 0 Then
Set doc = dc.GetFirstDocument
' get Keywords for domain
urlkeyword = "Domain"
Set keywordview = db.GetView( "lookupkeywords" )
Set urlkeyworddoc = keywordview.GetDocumentByKey( Lcase( urlkeyword ))
If urlkeyworddoc Is Nothing Then
Msgbox "Fatal Error - Keyword: " + urlkeyword + " not found",, "Fatal error"
Exit Sub
Elseif urlkeyworddoc.KeywordList(0) = "" Then
Msgbox "Fatal Error - Keyword: " + urlkeyword + " has no value",, "Fatal error"
Exit Sub
End If
While Not doc Is Nothing
' get parent Instruction
Set insdoc = db.GetDocumentByUNID( doc.ParentDocumentUNID )
' generate an invoice number and date apply it to the invoice and copy to the parent document
If Not insdoc Is Nothing Then
'If the parent doc has an invoice number then return an error
If insdoc.invoiceNo(0) <> "" Then
'Parent document has an invoice number already
Msgbox "Parent document " + insdoc.referenceNo(0) + " has an invoice number: " + insdoc.invoiceNo(0)
Else
'Parent document has no invoice number"
' generate the invoice number
insCount = countDoc.Count(0)+1
countDoc.Count = insCount
Call countDoc.Save( True, True )
invoiceNo = "NPS" + Cstr(insCount)
' save it to the invoice
doc.invoiceNo = invoiceNo
doc.invoiceDate = Now
Call doc.Save( True, False )
' save it to the parent document
insdoc.fee = doc.feeAmt(0)
insdoc.feeVAT = doc.feeAmtVAT(0)
insdoc.invoiceNo = invoiceNo
insdoc.invoiceDate = Now
Call insdoc.Save( True, False )
' set filename and url for document, create pdf
responsesview = "lookupinvoicesbyunid"
filename = |c:\temp\| & invoiceNo & |.pdf|
url = urlkeyworddoc.KeywordList(0) & |/| & directory & |/| & db.FileName & |/| & responsesview & |/| & doc.UniversalID & |?opendocument|
Print url
Call MakePDF( url, filename )
If Lcase(directory) = "npstest" Then
subject = "TEST SYSTEM - Invoice for: " & doc.referenceNo(0) & " (" & doc.cliName(0) & " - Client Ref: " & doc.acNo(0) &")"
Else
subject = "Invoice for: " & doc.referenceNo(0) & " (" & doc.cliName(0) & " - Client Ref: " & doc.acNo(0) &")"
End If
message = |Invoice for | & doc.referenceNo(0) & | client ref. | & doc.acNo(0) & | attached.|
If EmailReport( doc.SendInvoiceTo, "", doc.SendInvoiceBlindCopyTo, subject, message, filename ) Then
' update parent status history and date
Set nam = New NotesName( doc.SendInvoiceTo(0) )
history$ = Cstr(Today) & ": Invoice sent to: " & nam.Common
Set item = insdoc.GetFirstItem( "insStatus" )
Call item.AppendToTextList( history$ )
Call insdoc.Save( True, False )
' create report record
Call ReportRecord( insdoc, filename, "Invoice", history$ )
' flag invoice doc for deletion
doc.Form = "frmInvoiceDeleted"
Call doc.Save( True, False )
Set deldoc = doc
' delete file
Kill filename
End If
End If
End If
NextDoc:
Set doc = dc.GetNextDocument( doc )
' hard delete invoice doc
If Not deldoc Is Nothing Then
If deldoc.Form(0) = "frmInvoiceDeleted" Then
Call deldoc.Remove( True )
End If
End If
Wend
End If
Exit Sub
ErrorHandling:
errMsg = session.CurrentAgent.Name + " Error " + Error + " on line " + Cstr(Erl)
Msgbox errMsg
If Error = "Unable to send mail, no match found in Name & Address Book(s)" Then
Resume nextDoc
End If
End Sub