kspuea
asked on
Creating DocLink in current editable uidoc using LotusScripts
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("UseCaseL ink")
Set docData = vLookupData.GetDocumentByK ey(doc.Log No(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.AppendDocLin k(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("Attach Data")
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
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
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("UseCaseL
Set docData = vLookupData.GetDocumentByK
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,
Set object = rtitem.EmbedObject(1454, "Microsoft Excel Worksheet", AttachFilePath(0))
Call docData.Save(True, False)
Call rtitemDocLink.AppendDocLin
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("Attach
Call docData.RemoveItem("$FILE"
Call docData.Save(True, False)
Set rtitem = New NotesRichTextItem(docData,
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
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.