• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

Create document number with Lotus script?

I need a simple Lotus script which gives the forms a unique document id.
The doc id should look like this:
Country name + number e.g. England-1 or German-2 etc.
I made a Sequence Doc and it should contain the number (always the highest)
I tried to create it but I'm not as good as I thought.
This is what I wrote till now:
If doc.DocNo(0) = "" Then
      Set view = db.GetView( "Sequence" )
      Set seqdoc = view.GetDocumentByKey( )
      If Not ( seqdoc Is Nothing ) Then
      seqdoc.SequenceNo = seqdoc.SequenceNo(0)+1
            Call seqdoc.save(True, False)
            doc.DocNo = seqdoc.SequenceNo(0)
            doc.FullDocNo = doc.CountryCodeFNumber(0) + "-" + Trim(Str(seqdoc.SequenceNo(0)))
                              
               End If
End If
   Call doc.save(True, False)
0
attila01
Asked:
attila01
  • 3
  • 3
1 Solution
 
HappyFunBallCommented:
I take it your sequence view only has one document in it?  And this script essentially does nothing when you run it?  Let me know if I'm off base as that would change my answer.  However, assuming I'm right, you just need to change the 3rd line from this:

 Set seqdoc = view.GetDocumentByKey( )

to this:

 Set seqdoc = view.GetFirstDocument()

I've never seen the GetDocumentByKey method without a parameter in it.  According to Help, the keyarray is a required parameter.  
0
 
attila01Author Commented:
I gave a value to the GetDocumentByKey method.
It works but I don't know if it's really the best way I did.
Could you take a look at it?
CountryCodeFNumber is a Field contains the country name.

If doc.DocNo(0) = "" Then
    Dim user As String, CountryCodeFNumber As String
      Dim nam As NotesName
      Dim counter As Integer
                        
      Set view = db.GetView( "Sequence" )
      Set seqdoc = view.GetDocumentByKey(doc.CountryCodeFNumber )
            If Not ( seqdoc Is Nothing ) Then
            seqdoc.SequenceNo = seqdoc.SequenceNo(0)+1
                  Call seqdoc.save(True, False)
                  doc.DocNo = seqdoc.SequenceNo(0)
                  doc.FullDocNo = doc.CountryCodeFNumber(0) + "-" + Trim(Str(seqdoc.SequenceNo(0)))
0
 
HappyFunBallCommented:
I see that you've dim'ed the CountryCodeFNumber variable as a String, but you don't use the variable in the code below.  When you access an item within a document, as you do with "doc.CountryCodeFNumber", you're accessing a property of the document object, and you don't need to setup a variable to do that.  

I don't see any other issues with the code.  As long as the Sequence view has its first column sorted, and that first column is a list of country names, then the GetDocumentByKey method should get the correct Sequence number document.  The rest of the code, that increments the sequence number and puts it on the current document, looks fine.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
attila01Author Commented:
You mean I can delete the line:
CountryCodeFNumber As String ?

And is the following line OK?
 Set seqdoc = view.GetDocumentByKey(doc.CountryCodeFNumber )
I mean, would it work without the "doc" word?
I give you the points but please answer me these questions.
Thanks

0
 
HappyFunBallCommented:
When you write 'doc.CountryCodeFNumber', you are referring to the NotesDocument object called doc that has an item within it it called CountryCodeFNumber.  Lotusscript allows you to refer to an item within a document using that simple 'property' syntax.  If you had an item in a document called Subject, you could access the value of the subject field using doc.Subject.

Now, don't confuse that with creating a variable named CountryCodeFNumber.  doc.CountryCodeFNumber and the variable you created called CountryCodeFNumber are two separate things.  doc.CountryCodeFNumber actually exists on the document and is saved to disk, whereas the variable CountryCodeFNumber is just in memory while you're running the script.  So, unless you're using that variable somewhere else in your code, it is ok to delete it.

The line Set seqdoc = view.GetDocumentByKey(doc.CountryCodeFNumber) looks ok to me.  

So does the script work now for you?
0
 
attila01Author Commented:
Yes, it works ok.

Thanks,
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now