Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LotusScript- create doclinks

Status
Not open for further replies.

surad

Technical User
Mar 10, 2003
37
US
I am looking for a Notes LotusScript that does the following:
I have a parent document that has children documents, where I want to
create links (Doclinks) of the children in a richtext field in the parent
document.
 
I'm a beginner, just to warn you before I start...

In the system we have in this office, (I don't know if this is just us, or if its Lotus standard, sorry) the child documents all contain a field called ProfilUniqueDocID, containing the Document ID of the parent. If you have this or something similar, then I can give you some help, although to actually write the agent I would need a lot more time, and to see exactly how your system handles this.

The only way I can think of to do this, which is for sure not the most efficient way, is to simply run a search through the database for the documents which contain this field with the same value as the profile document, and then append the document links in to a Rich Text field in the profile document. Using notesDatabase.AllDocuments would provide a list which you could loop through to locate and retrieve these documents, and then NotesRichTextItem.AppendDocLink would allow you to attach the links.

Sorry this isn't much help, but hey, I tried... :)
 
Got it! All you need to do is create a hotspot with the following LotusScript code in the "Click" event:

Please bear in mind that I don't have a test environment at work (where I am now) so this is all theory, and I haven't tried it. My advice is to get somebody to look this over before you use it, or use it in a test environment where you won't ruin anything! But here's my attempt anyway...

Sub Click (Source As Button)
Dim s As new NotesSession
Dim db As NotesDatabase
Dim linkField As NotesRichTextItem
Dim doc as NotesDocument
Dim ws As New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim parentDoc as NotesDocument

Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set db = s.CurrentDatabase
Set parentDoc = db.GetDocumentByUNID(doc.ParentDocumentUNID)
Set linkField = parentDoc.NAME_OF_FIELD
Call linkfield.AppendDocLink(doc, "Child Document")
End Sub

Good luck, and let me know if this is wrong - if it is, I'll change it or remove it so as not to leave bad code up here for others to use!
 
I also need help creating links in Notes documents. Currently, I have an agent that will detach embeddeded attachments and save them in newly created folders in a specified network directory.

The step I need help with is the creation of a link to the folder that the attachments were detached to. I'd like to put the link in the same field where the attachments used to reside. I don't need a link to each individual attachment, I only need one link to the folder that contains all the attachments

Below is my agent in its current state. If anyone knows some script that can take care of this, I'd really appreciate any help.

Sorry if my code is very amateur-ish, the only training I had was one VB class about 3 years ago. :) I'm thinking the code I need should be placed just after the Forall loop.

**************************************************************

Sub Initialize

Dim s As New NotesSession
Dim DC As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As Variant
Dim flag As Integer
Dim path As String
Dim rev As Integer
Dim info As String

Set DC = s.CurrentDatabase.UnprocessedDocuments
Set Doc = DC.GetFirstDocument
Do Until Doc Is Nothing
Print "Current document: " + Cstr(doc.ProposalNumber(0))
If (doc.HasEmbedded) Then 'checks if doc has attachments
flag = 0 'working on FIRST attachment
path = "C:\PAS_ARCHIVE_ATTACHMENTS\" + Cstr(doc.ProposalNumber(0))
If (doc.HasItem("ProposalRevNum")) Then 'checks if doc has Revision Number field
Dim num As String
num = Cstr(doc.ProposalRevNum(0))
If (num = "") Then 'doc has Revision Number field, BUT is empty
rev = 1
Else 'doc has Revision Number
rev = 0
End If
Else 'doc does NOT have Revision Number
rev = 1
End If
Set rtitem = doc.GetFirstItem("ProposalAttachment")
If (rtitem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then
If flag = 0 Then 'working on FIRST attachment
If rev = 0 Then 'doc has Revision Number
path = Ucase(path)
info = Dir(path, 16)
info = Ucase(info)
If (info = "") Then
Mkdir(path) 'creates new folder based on Proposal Number
path = path + "\" + Cstr(doc.ProposalRevNum(0))
Mkdir(path) 'creates new subfolder based on Revision Number
Else
path = path + "\" + Cstr(doc.ProposalRevNum(0))
Mkdir(path)
End If
Else 'doc does NOT have Revision Number
path = Ucase(path)
info = Dir(path, 16) 'checks for existence of Proposal Number folder
info = Ucase(info)
If (info = "") Then
Mkdir(path) 'creates new folder based on Proposal Number
End If
End If
End If
flag = 1
End If
Call o.ExtractFile(path+"\"+o.Source)
Call o.Remove
Call doc.Save(True,True)
End Forall
End If
End If
Set Doc = DC.GetNextDocument(Doc)
Loop
End Sub

Greatness is best measured by one's willingness to be kind. :)
 
Problem solved. All I needed was...

Call rtitem.AppendText("File:G:\..." + Cstr(doc.ProposalNumber(0)))
Call doc.Save(True, True)

...just after the Forall loop. All is well. :)

Greatness is best measured by one's willingness to be kind. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top