?
Solved

Lotus Notes Document ID

Posted on 2004-11-24
10
Medium Priority
?
1,999 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:emem
  • 5
  • 3
  • 2
10 Comments
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12672433
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
 

Author Comment

by:emem
ID: 12672648
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
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12672787
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Expert Comment

by:Bozzie4
ID: 12672802
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
 

Author Comment

by:emem
ID: 12672906
i did remove doc1...how will I set a new ids for other newly created documents?
0
 
LVL 15

Accepted Solution

by:
Bozzie4 earned 210 total points
ID: 12673229
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
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 90 total points
ID: 12692656
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 12944132
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
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12944411
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 12948248
Sorry, didn't read the whole thread again, just saw the accepted answer.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question