Paste content from clipboard into rtfield inside a new section - lotus-notes

I have a big problem =)
I copy the hole body content of an email to the clipbard and need to paste this content in a richtextfield.
My problem is now, to paste this content from clipboard inside a section.
So i have to create a section in the current Richtextfield the user is into and paste the content from clipboard into this section.
I've tried it with diffrent methods but nothing works.
Maybe there's a solution with RTNavigators or ranges, but i have no idea.
Someone has a a possible solution for me?
thanks in advance
Dim s As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim currField As String
Dim rtitem As NotesRichTextItem
Dim style As NotesRichTextStyle
Dim color As NotesColorObject
Set uidoc = ws.Currentdocument
Set db = s.Currentdatabase
Dim DummyDoc As NotesDocument
Dim DummyRT As NotesRichTextItem
currField = uidoc.Currentfield
'Create DummyDoc
Set DummyDoc = db.CreateDocument
Call DummyDoc.Createrichtextitem("dummy")
Set DummyRT = DummyDoc.Createrichtextitem("DummyRT")
Call DummyDoc.Save(True,True)
'Open DummyDoc in workspace
Dim dummyUIDoc As NotesUIDocument
Set dummyUIDoc = ws.Editdocument(True, DummyDoc,True)
'Paste copied content
Call dummyUIDoc.Gotofield("dummy")
Call dummyUIDoc.Paste()
Call dummyUIDoc.Refresh(True,False,True)
Call dummyUIDoc.Save()
Call dummyUIDoc.Close(True)
'Create Section
Dim secUIDoc As NotesUIDocument
Set style = s.CreateRichTextStyle
Set color = s.CreateColorObject
Call DummyRT.BeginSection("", style, color, True)
Call DummyRT.EndSection
Call DummyDoc.Save(True, False, False)
Set secUIDoc = ws.EditDocument(True, DummyDoc)
Call DummyDoc.Remove(True)
Call secUIDoc.Gotofield("DummyRT")
Call secUIDoc.Selectall()
Call secUIDoc.Copy()
Call secUIDoc.Close(true)
'Paste generated content
Call uidoc.Gotofield(currField)
Call uidoc.Paste()
Dim range As NotesRichTextRange
Dim count As Integer
Dim nav As NotesRichTextNavigator
Set rtitem = uidoc.Document.Getfirstitem(currField)
Set range = rtitem.CreateRange
Set nav = rtitem.CreateNavigator
Call nav.FindFirstString("#PH#")
Call range.SetBegin(nav)
Call range.SetEnd(nav)
Call range.Remove
Call uidoc.Paste()
Second try
Dim s As New NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim currField As String
Dim rtitem As NotesRichTextItem
Dim style As NotesRichTextStyle
Dim color As NotesColorObject
Set uidoc = ws.Currentdocument
Set db = s.Currentdatabase
Dim DummyDoc As NotesDocument
Dim DummyRT As NotesRichTextItem
currField = uidoc.Currentfield
'Insert Section
Set DummyRT = uidoc.Document.Getfirstitem(currField)
Call DummyRT.Beginsection("",style,color,true)
Call DummyRT.Appendtext("Test")
Call DummyRT.Endsection()
Call uidoc.Reload()
Call uidoc.Gotofield(currField)
Call uidoc.Paste()

BreakingPar has code on accessing the windows clipboard: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFA00581AB2
You seemed to have some questions about using RTNavigators, and I think that's the way to go. Hoping it will be of assistance to you, I'm including a button I have that using RTNavigators to add a table in. I've not used sections, but I this may help.
Cheers,
Brian
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim firstDoc As NotesDocument
Dim tableDoc As New NotesDocument(db)
Set uidoc = ws.CurrentDocument
Dim univID As String
Set firstDoc = uidoc.Document
univID = firstDoc.UniversalID
Call uidoc.Close
Msgbox univID
Dim tableItem As NotesRichTextItem
Call tableDoc.ReplaceItemValue("Form","Table Holder")
Dim body As New NotesRichTextItem(tableDoc,"BuiltTable")
rowCount% = 4
columnCount% = 4
'Order the table
Call body.AppendTable(rowCount%,columnCount%)
Dim rtnav As NotesRichTextNavigator
Set rtnav = body.CreateNavigator
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
For iRow% = 1 To rowCount% Step 1
For iColumn% = 1 To columnCount% Step 1
Call body.BeginInsert(rtnav)
Call body.AppendText("Row " & iRow% & ", Column " & iColumn%)
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Next
Next
Call tableDoc.Save(True, False)
Set tableItem = tableDoc.GetFirstItem("BuiltTable")
'Call tableItem.CopyItemToDocument(doc,"TableTarget")
Call tableItem.CopyItemToDocument(firstDoc, "TableTarget")
Call firstDoc.Save(True,False)
Call ws.ViewRefresh
Call ws.EditDocument(True,firstDoc,False)
End Sub

Or, if you know the name of the origin field, you can use the code below to copy the RT field from one document to another. "NewLink" is the name of my origin field.
Cheers,
Brian
Dim thisDoc As NotesDocument
Dim thisRT As Variant
Dim newRT As Variant
Dim newDoc As NotesDocument
Set uiws = New NotesUIWorkspace
Set sess = New NotesSession
Set db = sess.CurrentDatabase
Set thisuidoc = uiws.CurrentDocument
Set thisDoc = thisuidoc.Document
Set thisRT = thisDoc.GetFirstItem("NewLink")
Set newDoc = db.CreateDocument
newDoc.Form = "RT"
Call newDoc.Save(True,False)
Set newRT = New NotesRichTextItem(newdoc,"newRTfield")
Call thisuidoc.Close
Call newRT.AppendRTItem(thisRT)
Call newdoc.Save(True,False)
Set newuidoc = uiws.EditDocument(True, newDoc)

Related

Can we able to export the file using Freefile with form fields instead of views in lotus notes

I'm trying to generate a csv file from lotus notes. Is it possible to get field values from form using freefile? In my case the views doesn't show all the fields which i'm looking for. I have referred some of the sites but no answer. Please help me.
Thanks in advance
I have tried this code atleast to print header but its not working
Dim db As NotesDatabase
Dim uiview As NotesUIView
Dim vw As NotesView
Dim doc As NotesDocument
Dim form As NotesForm
Dim session As NotesSession
Dim Field As NotesItem
Dim fileName As variant
Dim Date1(1 To 3) As String
Dim headerString As String
Dim header As Variant
Dim fieldString As String
Dim fieldList As Variant
Dim i As Long, j As Long,seqno As Integer,count As Long
Dim fileNum As Integer
Dim rowstring As String
Dim cns As String
Sub Initialize
Set uiview = ws.CurrentView
Set view = uiview.View
Set session=New NotesSession
Set db = session.CurrentDatabase
fileName = ws.SaveFileDialog(False,"File name",, "E:\samp" & ".csv")
Call Exit_Form(db)
End Sub
Function Exit_Form(db As NotesDatabase)
fileNum% = FreeFile()
Open fileName For Output As fileNum%
On Error GoTo errorhandler
headerString ="UNID,S.No,SectionName,Year,Discount,Formula,Final Price"
header = Split(UCase(headerString),",")
Set form=db2.Getform("Form1")
i=1
j=1
count1=0
ForAll a In header
Print #fileNum%, a
End ForAll
errorhandler:
MsgBox "ExitForm function" +Error + CStr(Erl)
Exit Function
End Function
You are using the wrong classes.
A "Form" is a design element to show "Documents" in a NotesDatabase. There is no information about the data in there.
You need to get NotesDocument- Objects, and from there you can read the data using GetItemValue- Method.
In addition I would not use the "antique" technique of freefile but use the class "NotesStream" for it.
To e.g. export all documents in a database (means: all different forms are used) you can do something like:
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
Dim stream as NotesStream
Dim lineInFile as String
Dim itemList as Variant
Dim i as Integer
Set db = ses.CurrentDatabase
Set dc = db.AllDocuments
Set stream = ses.CreateStream
....
Call stream.Open( fileName )
Call stream.WriteText( headerLine, EOL_CRLF )
itemList = Split( "ItemFromDocument1,ItemFromDocument2,...", "," )
Set doc = dc.GetFirstDocument()
While not doc is Nothing
For i = 0 to ubound( itemList )
If i = 0 then
writeLine = Cstr( doc.GetItemValue( itemList(i) )(0) )
Else
writeLine = writeList & "," & Cstr( doc.GetItemValue( itemList(i) )(0) )
End If
Next
Call stream.WriteText( writeLine, EOL_CRLF )
Set doc = dc.GetNextDocument(doc)
Wend
Call stream.Close
You could do the same with all documents in a specific folder or view:
Dim view as NotesView
Set view = db.GetView( "NameOfFolderOrView" )
...
Set doc = view.GetFirstDocument()
While not doc is Nothing
...
Set doc = view.GetNextDocument( doc )
Wend
Beware: This approach is quite ugly. It does not consider multi value fields, it does not escape commas that are probably in one of the field values and it does not have any error handling... but at least it is a start.

How to include a DocLink in a MIME Email in Lotus Notes?

I wish to obtain the DocLink or the value of the link about the document to include in a MIME email using LotusScript, but I don't know how to do it.
I have this:
Sub Click(Source As Button)
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False
Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message")
Set header = body.CreateHeader("To")
Call header.SetHeaderVal("email_domain")
Call stream.writetext(|<HTML>|)
Call stream.writetext(|<body>|)
user$ = s.CommonUserName
Call stream.writetext(|<br><font size="+5" color="red">| & user$ &|</font>|)
Call stream.WriteText(|<br>Notes<br>|)
Call stream.writetext(|</body>|)
Call stream.writetext(|</html>|)
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True
End Sub
In this code I can include the <a></a> tags with an URL Notes, but I really want to generate the link of this document like using the AppendDocLink.
Is it possible?
Finally I have found a solution with UniversalID. I retrieve this ID of the document and I add to the URL, like this.
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim doc2 As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Dim urldoc As String
Set doc2 = ws.CurrentDocument.Document
Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False
urldoc = doc2.UniversalID
Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message")
Set header = body.CreateHeader("To")
Call header.SetHeaderVal("email")
Call stream.writetext(|<HTML>|)
Call stream.writetext(|<body>|)
user$ = s.CommonUserName
Call stream.writetext(|<br><font size="+5" color="red">| & user$ &|</font>|)
Call stream.WriteText(|<br>Notes<br>|)
Call stream.writetext(|</body>|)
Call stream.writetext(|</html>|)
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True
End Sub

"GetAllDocumentsByKey" Can not get all document by key

My problem is when use GetAllDocumentByKey for get all document that's contain "keys" is multiple keys but the result from use below code can't get all
such as sometimes is returned only 2 document, but it's should return 5 document that's contains that's keys.
How should I solve this problem?
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim dc As NotesDocumentCollection
Set db = session.CurrentDatabase
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim doc As NotesDocument
Dim keys( 0 To 1 ) As Variant
'Dim vc As NotesViewEntryCollection
Dim defect As Variant
defect = uidoc.FieldGetText("DefectMode")
keys( 0 ) =defect
Dim PartNo As Variant
partNo = uidoc.FieldGetText("PartNo")
keys( 1 ) = partNo
Set view = db.GetView("EmbedView2" )
Set dc = view.GetAllDocumentsByKey(keys,False)
'Set vc=db.GetView("EmbedView2")
Call dc.PutAllInFolder("EmbedFolder")
Call workspace.DialogBox( "Embedded form", True, True, True, True, False, False, "Select Part No",,True,True )
'Call dc.RemoveAllFromFolder( "EmbedFolder" )
End Sub
Did you tried to proceed each keys value separately ?
Set view = db.GetView("EmbedView2" )
ForAll key in keys
Set dc = view.GetAllDocumentsByKey(key,False)
Call dc.PutAllInFolder("EmbedFolder")
end ForAll
[Edit] In order to understand where is the problem, check if your keys really return data. See the output for each key.
Set view = db.GetView("EmbedView2" )
ForAll key in keys
Set dc = view.GetAllDocumentsByKey(key,False)
print "*** for " + key + " number or matching: " & dc.Count
Call dc.PutAllInFolder("EmbedFolder")
end ForAll

NotesAgent.Run method always returns 0 no matter what

All,
I have the following problem. I want to launch an agent and want it to communicate back to the calling script if things went OK or if something went less OK.
I tried to use a solution that seems obvious, the return value of the NotesAgent.Run
My agent looks like this (Terminate sub routine is empty)
Sub Initialize
Set ws = New NotesUIWorkspace
Set uidoc = ws.Currentdocument
Set doc = uidoc.Document
Set pass = doc.Getfirstitem("Passcode")
Error 1144
' log information here
End Sub
I am calling(or launching if you may) the agent like this
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Set agent = db.GetAgent("MyAgent")
returnVal% = agent.Run
Messagebox "It returned " & returnVal%
End Sub
If I take out the Error statement the logs get updated, and that doesn't happen if I leave there the Error statement, so it is definitely causing an error. But the Message box always prints stubbornly "It returned 0". I also tried to put the Error statement on Terminate. Result was the same, unfortunately ..
Could you please kindly point me where I'm going sideways on this ? I was expecting this to be simple.
Thank you
Kind Regards,
Carlos
This method returns a value that indicates that the agent is started or did not started. It does not return the result of the agent itself. If the agent is started, but during its work the agent made an error, then this method returns 0, because the agent is started.
0. To recieve a status from agent you can use the in-memory document as described here.
Your agent:
Sub Initialize
Set ws = New NotesUIWorkspace
Set uidoc = ws.Currentdocument
Set doc = uidoc.Document
Set pass = doc.Getfirstitem("Passcode")
Dim ses As New NotesSession
Dim docContext = ses.DocumentContext
Call docContext.ReplaceItemValue("ReturnVal", 1444)
' log information here
End Sub
Call the agent like this:
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Set agent = db.GetAgent("MyAgent")
Call agent.RunWithDocumentContext(doc)
returnVal% = doc.ReturnVal(0)
Messagebox "It returned " & returnVal%
End Sub
1. If you cannot use in-memory document then you need to save document and reopen it.
Your agent:
Sub Initialize
Set ws = New NotesUIWorkspace
Set uidoc = ws.Currentdocument
Set doc = uidoc.Document
Set pass = doc.Getfirstitem("Passcode")
Dim ses As New NotesSession
Dim agent As NotesAgent
Dim db As NotesDatabase
Dim docContext As NotesDocument
Set agent = ses.CurrentAgent
Set db = ses.CurrentDatabase
Set docContext = db.GetDocumentByID(agent.ParameterDocID)
Call docContext.ReplaceItemValue("ReturnVal", 1444)
Call docContext.Save(False, False)
' log information here
End Sub
Call the agent like this:
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Call doc.Save(False, False)
noteID$ = doc.NoteID
Set agent = db.GetAgent("MyAgent")
Call agent.Run(noteID$)
Delete doc
Set doc = db.GetDocumentByID(noteID$)
returnVal% = doc.ReturnVal(0)
Messagebox "It returned " & returnVal%
Call doc.Remove(True)
End Sub
I believe you need to use the RunOnServer() method, which according to the documentation is synchronous:
http://www.ibm.com/developerworks/lotus/library/ls-Troubleshooting_agents_ND5_6/
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Set agent = db.GetAgent("MyAgent")
returnVal% = agent.RunOnServer()
Messagebox "It returned " & returnVal%
End Sub

Filter Process script Library

I have a form called Approver in "Approver" db.
The form has two editable text fields: Office and Group. It also has a dialog list field superior1.
The superior1 dialog list field should show the staff details filtered based on office & group:
if office = TSP & group = HR from the approver form, then shud filter the staffs based on these fields group" & "office" with the "Staff info" view of another database "TSP_Staff" and show in superior1.
But it is not getting filtered for me. :(
I am new to this tech, so I am confused and have no one to help me in this. This is the script I used:
for the superior1 field:
Sub Entering(Source As Field)
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim uidoc As NotesUIDocument
Dim doc As Notesdocument
Dim work As New NotesUIWorkspace
Dim workspace As New NotesUIWorkspace
Dim sname As String
Dim consr As String
Dim cview As notesview
Set db = s.CurrentDatabase
Set uidoc = work.CurrentDocument
Set uidocs = workspace.currentdocument
Set cview = db.getview("(Application)")
'etype = uidoc.FieldGetText("Office")
'ftype = uidoc.FieldGetText("Group")
etype = "TSP"
ftype = "TSP1-G"
If(etype <> "" And ftype <> "") Then
Call filter
End If
Set view = db.getview("(x_search_staff)")
Set doc = view.GetDocumentByKey (uidoc.fieldgettext("Superior1"),True)
If doc Is Nothing Then
Msgbox "There is no previous transaction please select new trasaction.", 16, "Information"
Call uidoc.FieldClear("Superior1")
Call uidoc.gotofield ("Group")
Call uidoc.gotofield ("Office")
continue = False
Exit Sub
End If
Call uidoc.Refresh
End Sub
from the script library ...
Sub filter
Dim s As New notessession
Dim w As New notesuiworkspace
Dim uidoc As notesuidocument
Dim doc As notesdocument, newdoc As notesdocument, d As notesdocument, dd As notesdocument
Dim doc1 As NotesDocument, newdoc1 As NotesDocument
Dim dc As notesdocumentcollection
Dim bc As notesdocumentcollection
Dim view As notesview, v As notesview
Dim db As notesdatabase
Dim nextdoc As NotesDocument
Dim cview As notesview
Dim cnview As NotesView
Dim get_db As New notesdatabase(gsserver2, gspath2 & "Master\TSP_Staff.nsf")
Set db = s.currentdatabase
Set view = get_db.getview("(Staff Info)")
Set cview = db.getview("(x_search_staff)")
Set cnview = db.getview("(x_superior)")
Set uidoc=w.CurrentDocument
'To delet searched previous datas from form2 ----------------------------------------
Print "Please wait ..."
key = "Approver2"
Set v = db.getview("(x_delete_2)")
Set dc = v.GetAlldocumentsByKey(key,True)
'Set bc = v.GetAlldocumentsByKey(key,True)
'Call bc.RemoveAll(True)
Call dc.RemoveAll(True)
Call cview.Refresh
Call view.Refresh
Call cnview.Refresh
Call v.Refresh
'To start searching process based on Superior1 --------------------------------------
'f1= uidoc.FieldGetText("Office")
f1= uidoc.FieldGetText("Group")
'f1 = "TSP1-G"
Set dc = view.getalldocumentsbykey(f1, True)
'Set bc = view.getalldocumentsbykey(f2, True)
For b =1 To dc.count
Set doc = dc.getnthdocument(b)
Set newdoc = doc.copytodatabase(db)
'For c =1 To bc.count
'Set doc1 = bc.getnthdocument(b)
'Set newdoc1 = doc.copytodatabase(db)
If doc.form(0) = "Approver" Then
'If doc1.form(0) = "Approver" Then
newdoc.form = "Approver2"
'newdoc1.form = "Approver2"
'End If
End If
newdoc.save True, True
' Next
'newdoc.save True, True
'Next
Call w.viewrefresh
Call cview.Refresh
Call v.Refresh
Call cnview.Refresh
Call view.Refresh
Print "Process Completed....."
End Sub
if u got another way for this requirement temme in stepwise wat to do... or else... chk out ma script for errors... hope u help me :( today due date for this task...
I'm not sure how smart it is to filter the documents shown in a view by deleting documents from a database :)
My suggestion is to first post the code properly. This is simply unreadable.
How to display only subset of documents in your dialog list?
Create a hidden field on your form (you'll fill it with values you want displayed in the list using your code).
And then, on your dialog list field properties, second tab, set choices option to be "Use formula for choices" and set it to be the hidden field name.
Ask if you need more help...
Your code is very hard to follow, but if I understand your intention and parts of the filter function (does it even compile?) you could replace all of the code with this #dblookup-based formula in "use formula for choices" section of superior1 properties:
#dblookup("":"ReCache";"ServerName":"foo\Master\TSP_Staff.nsf";"(Staff Info)";Group;NameOfInterestingField);
You might want to add a #sort and/or #unique around it if the view contain duplicate values, and you might want to add the keyword [FAILSILENT] if some groups should result in an empty list.
An even simpler method could be to configure superior1 to use view dialog for choices.

Resources