?
Solved

Creating DocLink in current editable uidoc using LotusScripts

Posted on 2006-05-15
4
Medium Priority
?
722 Views
Last Modified: 2013-12-18
Hi,

I have a button on a form.
And I want to create a doclink & paste it in a RichTextField in my uidoc after clicking the button to create a document in another db.

So far, the doc will be created in another db successfully, but it just doesn't create a doclink of it in my uidoc when/after I save.
Any problems with my program?
Or is there any other way to create the same effect as my program?

Thanks alot in advance!

Here is my codes of the hotspot button.

      Dim ws As New NotesUIWorkspace
      Dim sess As New NotesSession
      Dim db As NotesDatabase, dbData As NotesDatabase
      Dim vProf As NotesView, vLookupData As NotesView
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument, docProf As NotesDocument, docData As NotesDocument
      Dim rtitem As NotesRichTextItem, rtitemDocLink As NotesRichTextItem, item As NotesItem
      Dim AttachFilePath As Variant, object As NotesEmbeddedObject
      
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.Document
      Set db = sess.CurrentDatabase
      Set vProf = db.GetView("vMaintAppSetup")
      Set docProf = vProf.GetFirstDocument
      Set dbData = sess.GetDatabase(db.Server, docProf.MaintDataFilePath(0))
      Set vLookupData = dbData.GetView("vAll")
      
      AttachFilePath = ws.OpenFileDialog(False, "Select File to attach...", "", "c:", "")
      If Not Isempty(AttachFilePath) Then
            'Set rtitemDocLink = New NotesRichTextItem(doc, "UseCaseLink")
            Set rtitemDocLink = doc.GetFirstItem("UseCaseLink")
            
            Set docData = vLookupData.GetDocumentByKey(doc.LogNo(0), True)
            If docData Is Nothing Then  'If current doc is new Data
                  Set docData = New NotesDocument(dbData)
                  docData.Form = "frmData"
                  docData.LogNoData = doc.LogNo(0)
                  Set rtitem = New NotesRichTextItem(docData, "AttachData")
                  Set object = rtitem.EmbedObject(1454, "Microsoft Excel Worksheet", AttachFilePath(0))
                  Call docData.Save(True, False)
                  Call rtitemDocLink.AppendDocLink(docData, "Attachment")
                  Call doc.Save(True, False)
                  Call uidoc.Refresh(True)
                  Call uidoc.Save
                  Call uidoc.Close
                  
            Else  'Existing Data
                  'remove the existing attachment & attach the new one into
                  Call docData.RemoveItem("AttachData")
                  Call docData.RemoveItem("$FILE")
                  Call docData.Save(True, False)
                  
                  Set rtitem = New NotesRichTextItem(docData, "AttachData")
                  Set object = rtitem.EmbedObject(1454, "Microsoft Excel Worksheet", AttachFilePath(0))
                  Call docData.Save(True, False)
                  Call doc.Save(True, False)
                  Call uidoc.Save
                  Call uidoc.Close
            End If
      Else
            Msgbox "Cannot attach file!", 0+16, "Errors"
            Exit Sub
      End If
0
Comment
Question by:kspuea
  • 2
4 Comments
 
LVL 19

Assisted Solution

by:madheeswar
madheeswar earned 200 total points
ID: 16681020
Instead of this: and I assume Attachment is an RTF field.
 Call docData.Save(True, False)

 Call rtitemDocLink.AppendDocLink(docData, "Attachment")

use this:
 Call rtitem.AppendDocLink(docData, "Please click on this Attachment")
 Call docData.Save(True, False)
0
 

Author Comment

by:kspuea
ID: 16686985
Hi madheeswar,

Sorry, I didn't make myself clear.

Actually, what I want to achieve by the program is, when the user clicks on the hotspot button in the current uidoc, it will let the user selects a file to attach, then it will save the selected file to a document in another database. Once the document is saved, create a doclink of it in the current uidoc's RichText field & save the current uidoc.

The "rtitemDocLink" is referred to the current uidoc's RichText field which I want to paste the doclink to.
The "rtitem" is referred to the document's RichText field in another db, which the program stores the selected file as attachment.
0
 
LVL 18

Accepted Solution

by:
marilyng earned 400 total points
ID: 16876956
In your last  ELSE section, you have:

             Call docData.Save(True, False)
             Call doc.Save(True, False)

when you didn't create a new document.  So, as madheeswar pointed out, you need to add the attachment call to the that section:
                Else  'Existing Data
               'remove the existing attachment & attach the new one into
               Call docData.RemoveItem("AttachData")
               Call docData.RemoveItem("$FILE")
               Call docData.Save(True, False)              
               Set rtitem = New NotesRichTextItem(docData, "AttachData")
               Set object = rtitem.EmbedObject(1454, "Microsoft Excel Worksheet", AttachFilePath(0))
               Call docData.Save(True, False)
               Call rtitemDocLink.AppendDocLink(docData, "Attachment")  '<<<here
               Call doc.Save(True, False)

Then you have to close and reopen the uidoc in order to see the attachment.

Caveat..
     if  doc is a new doc, then set rtItemDocLink  will create the initial instance of the rich text field.
     If the doc is not new, then you need to grab the existing rich text field using:
          Dim rtItemDocLink as variant
          set rtItemDocLink = doc.getfirstItem("thisRTField")
            if rtItemDocLink.Type = RICHTEXT then
                 'do something
            end if

Else what you get is another instance of the rich text field.  When the document has TWO fields of the same name, Notes will display the first and not the second.

So, you have to add checks for new doc in your code.

   
     
   
0
 

Author Comment

by:kspuea
ID: 16882601
Hi marilyng, madheeswar,

I got the program works finally!
Actually saw someone's answer from another forum too.

Yes, you're right, have to save the doc, then create the doclinks then re-open the doc.
I put the "appenddoclink" actions in the PostSave event of the form, & it works wonderfully!

Thanks very much for your help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

612 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