Lotus Notes Document ID

HI experts! got a simple question ...how can I create a document ID in lotusscript? heres the scenario ....I uploaded data from an excel sheet and stored it in a view ...I want to have those data uploaded to have a unique document id...how will i do this? here is a short part of my code

      If .Cells (row, 1).Value = "Return on Equity" And .Cells(row,2).Value= "Return on Sales." And .Cells (row, 3).Value = "Liquidity/Financing Structure" And .Cells(row,4).Value= "Financial Leverage" And .Cells (row, 5).Value = "Asset Turnover" And .Cells(row,6).Value= "Profit Consistency" And .Cells (row, 7).Value = "Debit Service Cover" Then      
                        Goto Finish
                  End If
                  
                  doc.ROE = .Cells( row, 1 ).Value
                  doc.ROS = .Cells(row, 2 ).Value
                  doc.LFS = .Cells(row, 3).Value
                  doc.FL = .Cells( row, 4 ).Value
                  doc.AT = .Cells(row, 5).Value
                  doc.PC= .Cells( row, 6).Value
                  doc.DSC = .Cells(row, 7).Value
                  doc.CNAME = .Cells(row, 8).Value
                  doc.dtcreatd = Now()
                  doc.docid = nid => this is suppose to save a document id (nid I declare as a string with the following declarations to follow
                Set doc = New NotesDocument(db)
      Set doc1= New notesdocument(db)
      nid = doc.NoteID
did i do this right?

thanks hoping for your quck reply
ememAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bozzie4IT ArchitectCommented:
You don't create a 'document id' in Notes, it's created for you.  There are 2 'Note ID's', the Universal ID (32 characters) and the Note ID (smaller, I don't know -> I  never use it).  So no need to try and create it.

But what you want, is a unique key to be able to retrieve your document (I think?).  That does not make sense if you don't write back to your excel sheet, of course (right?)

So for now, just change your code (btw I don't understand your code , you may have other problems too with it !):

set doc = new notesdocument(db)
doc.form = "YOURFORM"
 doc.ROE = .Cells( row, 1 ).Value
               doc.ROS = .Cells(row, 2 ).Value
               doc.LFS = .Cells(row, 3).Value
               doc.FL = .Cells( row, 4 ).Value
               doc.AT = .Cells(row, 5).Value
               doc.PC= .Cells( row, 6).Value
               doc.DSC = .Cells(row, 7).Value
               doc.CNAME = .Cells(row, 8).Value
               doc.dtcreatd = Now()
             '  doc.docid = nid => THIS DOES NOTHING
 

Call doc.save(  true, false ) 'You need to save the document too... This will store the unid and noteid values.

cheers,

Tom
0
ememAuthor Commented:
tom here is my complete code...i save the data ..i have noted that doc.docid=nid....nid which i declared as a string and given the value of this => nid = doc.NoteID....below is the complete code ......

Sub Initialize
      Dim FileNum As Integer
      Dim xlFilename As String
      
      Filenum% = Freefile()
      'xlFileName$ = path_x
      Dim ws As New notesuiworkspace
      Dim curdoc As notesdocument
      Set curdoc=ws.currentdocument.document
     'Dim curdoc=ws.currentdocument.document
      xlFileName$ = curdoc.path_x (0)
      
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim nid As String
      Dim One As String
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set doc = New NotesDocument(db)
      Set doc1= New notesdocument(db)
      nid = doc.NoteID
      
      
      Dim row As Integer
      Dim written As Integer
      
 '// Next we connect to Excel and open the file. Then start pulling over the records.
      Dim Excel As Variant
      Dim xlWorkbook As Variant
      Dim xlSheet As Variant
      Print "Connecting to Excel..."
      Set Excel = CreateObject( "Excel.Application.8" )
      Excel.Visible = False '// Don't display the Excel window
      Print "Opening " & xlFilename & "..."
      Excel.Workbooks.Open xlFilename '// Open the Excel file
      Set xlWorkbook = Excel.ActiveWorkbook
      Set xlSheet = xlWorkbook.ActiveSheet
      
 '// Cycle through the rows of the Excel file, pulling the data over to Notes
      Goto Records
      
Records:
      row = 0 '// These integers intialize to zero anyway
      written = 0
      Print "Starting import from Excel file..."
      Do While True
Finish:
            With xlSheet
                  row = row + 1
                  Set view = db.GetView("fc")
                  Set doc = db.CreateDocument '// Create a new doc
                  doc.Form = "Financial Condition"
                  
                  If .Cells (row, 1).Value = "" And .Cells(row,2).Value = "" And .Cells (row, 3).Value = "" And .Cells(row,4).Value = "" And .Cells (row, 5).Value = "" And .Cells(row,6).Value = "" And .Cells (row, 7).Value= ""Then
                        Print "Disconnecting from Excel..."
                        xlWorkbook.Close False '// Close the Excel file without saving (we made no changes)
                        Excel.Workbooks.Close '// Close the Excel file      
                        Excel.Quit '// Close Excel
                        Set Excel = Nothing '// Free the memory that we'd used
                        Print " " '// Clear the status line
                        Messagebox  written &" Record(s) Uploaded Successfully.",MB_OK, "Uploading Excel Data"
                        Goto Done
                  End If
                  
                  If .Cells (row, 1).Value = "Return on Equity" And .Cells(row,2).Value= "Return on Sales." And .Cells (row, 3).Value = "Liquidity/Financing Structure" And .Cells(row,4).Value= "Financial Leverage" And .Cells (row, 5).Value = "Asset Turnover" And .Cells(row,6).Value= "Profit Consistency" And .Cells (row, 7).Value = "Debit Service Cover" Then      
                        Goto Finish
                  End If
                  
                  doc.ROE = .Cells( row, 1 ).Value
                  doc.ROS = .Cells(row, 2 ).Value
                  doc.LFS = .Cells(row, 3).Value
                  doc.FL = .Cells( row, 4 ).Value
                  doc.AT = .Cells(row, 5).Value
                  doc.PC= .Cells( row, 6).Value
                  doc.DSC = .Cells(row, 7).Value
                  doc.CNAME = .Cells(row, 8).Value
                  doc.dtcreatd = Now()
                  doc.docid = nid
                  
                  doc1.Form = "ImportForm1"
                  doc1.ROE = .Cells( row, 1 ).Value
                  doc1.ROS = .Cells(row, 2 ).Value
                  doc1.LFS = .Cells(row, 3).Value
                  doc1.FL = .Cells( row, 4 ).Value
                  doc1.AT = .Cells(row, 5).Value
                  doc1.PC= .Cells( row, 6).Value
                  doc1.DSC = .Cells(row, 7).Value
                  doc1.CNAME = .Cells(row, 8).Value
                  doc1.dtcreatd = Now()
                  doc.docid = nid
                  
                  Call doc.Save( True, False ) '// Save the new doc
                  
                  written = written + 1
                  Print written
            End With
      Loop
      Close #filenum      
      Return
Done:
End Sub
0
Bozzie4IT ArchitectCommented:
You set nid = doc.noteid, but ONLY for the first new document, so you will end up with all new documents having a field "docid" set to the noteid of the first newly created document.  I don't think that makes sense.

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Bozzie4IT ArchitectCommented:
What's the use of doc1 ?  That doesn't do anything (you don't save it): remove it !

Sub Initialize
     Dim FileNum As Integer
     Dim xlFilename As String
     
     Filenum% = Freefile()
     'xlFileName$ = path_x
     Dim ws As New notesuiworkspace
     Dim curdoc As notesdocument
     Set curdoc=ws.currentdocument.document
     'Dim curdoc=ws.currentdocument.document
     xlFileName$ = curdoc.path_x (0)
     
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView
     Dim nid As String
     Dim One As String
     Dim doc As NotesDocument
     Set db = session.CurrentDatabase
       
     Dim row As Integer
     Dim written As Integer
     
 '// Next we connect to Excel and open the file. Then start pulling over the records.
     Dim Excel As Variant
     Dim xlWorkbook As Variant
     Dim xlSheet As Variant
     Print "Connecting to Excel..."
     Set Excel = CreateObject( "Excel.Application.8" )
     Excel.Visible = False '// Don't display the Excel window
     Print "Opening " & xlFilename & "..."
     Excel.Workbooks.Open xlFilename '// Open the Excel file
     Set xlWorkbook = Excel.ActiveWorkbook
     Set xlSheet = xlWorkbook.ActiveSheet
     
 '// Cycle through the rows of the Excel file, pulling the data over to Notes
     Goto Records
     
Records:
     row = 0 '// These integers intialize to zero anyway
     written = 0
     Print "Starting import from Excel file..."
     Do While True
Finish:
          With xlSheet
               row = row + 1
               Set view = db.GetView("fc")
               Set doc = db.CreateDocument '// Create a new doc
               doc.Form = "Financial Condition"
               nid = doc.noteid
if nid="" then print "INVALID NOTEID"
               If .Cells (row, 1).Value = "" And .Cells(row,2).Value = "" And .Cells (row, 3).Value = "" And .Cells(row,4).Value = "" And .Cells (row, 5).Value = "" And .Cells(row,6).Value = "" And .Cells (row, 7).Value= ""Then
                    Print "Disconnecting from Excel..."
                    xlWorkbook.Close False '// Close the Excel file without saving (we made no changes)
                    Excel.Workbooks.Close '// Close the Excel file    
                    Excel.Quit '// Close Excel
                    Set Excel = Nothing '// Free the memory that we'd used
                    Print " " '// Clear the status line
                    Messagebox  written &" Record(s) Uploaded Successfully.",MB_OK, "Uploading Excel Data"
                    Goto Done
               End If
               
               If .Cells (row, 1).Value = "Return on Equity" And .Cells(row,2).Value= "Return on Sales." And .Cells (row, 3).Value = "Liquidity/Financing Structure" And .Cells(row,4).Value= "Financial Leverage" And .Cells (row, 5).Value = "Asset Turnover" And .Cells(row,6).Value= "Profit Consistency" And .Cells (row, 7).Value = "Debit Service Cover" Then    
                    Goto Finish
               End If
               
               doc.ROE = .Cells( row, 1 ).Value
               doc.ROS = .Cells(row, 2 ).Value
               doc.LFS = .Cells(row, 3).Value
               doc.FL = .Cells( row, 4 ).Value
               doc.AT = .Cells(row, 5).Value
               doc.PC= .Cells( row, 6).Value
               doc.DSC = .Cells(row, 7).Value
               doc.CNAME = .Cells(row, 8).Value
               doc.dtcreatd = Now()
               doc.docid = nid
               
               doc1.Form = "ImportForm1"
               doc1.ROE = .Cells( row, 1 ).Value
               doc1.ROS = .Cells(row, 2 ).Value
               doc1.LFS = .Cells(row, 3).Value
               doc1.FL = .Cells( row, 4 ).Value
               doc1.AT = .Cells(row, 5).Value
               doc1.PC= .Cells( row, 6).Value
               doc1.DSC = .Cells(row, 7).Value
               doc1.CNAME = .Cells(row, 8).Value
               doc1.dtcreatd = Now()
               doc.docid = nid
               

               Call doc.Save( True, False ) '// Save the new doc
               
               written = written + 1
               Print written
          End With
     Loop
     Close #filenum    
     Return
Done:
End Sub
0
ememAuthor Commented:
i did remove doc1...how will I set a new ids for other newly created documents?
0
Bozzie4IT ArchitectCommented:
It's in the code I last put in.  Just use that.

Anyway, there is not much use (well, there is, but probably not in your situation) in doing that, because you can always use @functions or Script to access the NoteID property.  Also, be aware that a NoteID CAN have a duplicate (certainly in other databases, but I suppose in the same db as well, although this should be very rare)

For instance, to sort the documents in a view by NoteID, put
@text(@noteid)
in the view column

cheers,

Tom
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwaleteeCommented:
Hi Bozzie4,

Why did you suggest .NoteID/@NoteID?  I would have used .UniversalID/@Text(@DocumentUnqiueID), which is much more stable.  It is a little hard to deal with though (32 characters), so we could use @Unique, which is shorter.

Best regards,
qwaletee
0
qwaleteeCommented:
Bozzie4,

> but I suppose in the same db as well,
Note ID is by definition unique to a documen in the database... the note ID points to an offset within a table that lists the location of all notes (documents) in teh file.  So, note ID=index to table, entry in table=location of document, note ID must be unique to document.  Th reason why a single note ID in one Db can refer to one document, and in another replica to a different document, is that they are created more or less sequentially.  So, if I create two documents at the same time in otheriwse byte-identical replicas, they will get the same note ID (but different UNIDs), since they will each occupy the "next available slot" in the document index.

It can also happen that a note ID is evetually re-used.  If a document is deleted, the deletion stub retains teh same note ID as the original document.  But if the deletion stub is purged, then the index position becomes available again, and could be re-used.

- qwaletee
0
Bozzie4IT ArchitectCommented:
Yes - completely correct -  I never use @noteID myself :-)

It was merely an example, and I only included it because the question (or a later question) was about the noteid.  I gave the heads-up too ...

cheers,

Tom
0
qwaleteeCommented:
Sorry, didn't read the whole thread again, just saw the accepted answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.