Can we able to export the file using Freefile with form fields instead of views in lotus notes - 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.

Related

"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

Paste content from clipboard into rtfield inside a new section

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)

Remainder Mail agent

I have form with 3 fields adress,status,ReportingDate.
Adress field contains the ID where the mil has to be sent.
Now I have created an agent where it should mail to the data present in adress field when status is incomplete and reporting date is exactly 7 days before todays date.
My Code:
Option Public
Option Declare
Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim timestamp As New NotesDateTime("Today")
Dim Noresponsedate As NotesDateTime
Dim vw As NotesView
Dim diff As Integer
Dim SendTo As Variant
Call timestamp.SetNow()
Set db = sess.CurrentDatabase
Set vw = db.GetView( "data" )
Set doc = vw.GetFirstDocument()
While Not doc Is Nothing
If doc.Status(0) = "Incomplete" Then
Call checktimedifference(doc)
End if
Set doc = vw.GetNextDocument(doc)
wend
End Sub
Sub checktimedifference(doc As NotesDocument)
Dim due As NotesDateTime
Dim present As NotesDateTime
Dim timecheck As variant
Set due = New NotesDateTime ( "" )
Set present = New NotesDateTime ( "Today" )
timecheck = doc.ReportingDate(0)
due.LSLocalTime = timecheck
If due.TimeDifference (present) = -604800 Then
Call sendmailtouser(doc)
End If
End Sub
Sub sendmailtouser(doc As NotesDocument)
Dim db As NotesDatabase
Dim rtiitem As NotesRichTextItem
Dim maildoc As NotesDocument
dim recepient As variant
Set maildoc = New NotesDocument( db )
Set rtiitem = New NotesRichTextItem( maildoc, "Body" )
recepient = doc.adress(0)
maildoc.from = db.Title
maildoc.form = "memo"
maildoc.subject = "A Minor Injury Report:" & doc.Seq_No(0) & " needs your response"
maildoc.SendTo = recepient
Call rtiitem.AppendText( "Please respond to this Minor Injury Report" )
Call rtiitem.AddNewline( 2 )
Call rtiitem.AppendText( "Your response for the Minor Injury Report: " & doc.Seq_No(0) & " is required" )
Call rtiitem.AddNewline( 2 )
Call rtiitem.AppendText( "Please click on the following link to access the document.")
Call rtiitem.AppendDocLink( doc, db.Title )
Call maildoc.Send(False)
End Sub
When I am running the agent on client I am getting the following error:
Please help me to solve the error and send mail to the recepients.
Not using any error handling is very bad practice. But your error will most probably happen in the sendmailtouser- sub, where you dim a local notesdatabase- object named db without actually initializing it.
The line
set maildoc = New NotesDocument( db )
will fail.
Either declare db globally and set it in your initialize or dim ses in that sub again and set db again (worst case as you have to do it for every document)

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.

Retrieving data from lotus NotesDatabase using lotusScript

I am new in lotusScript and lotus notes. I can retrieve data from database using notesView. Here is path of my lotusScript code for that:
Sub getViewData
Dim session As New NotesSession
Dim db As NotesDatabase
Dim mainDoc As NotesDocument
Set db = session.CurrentDatabase
Dim collection As NotesDocumentCollection
Set collection = db.AllDocuments
Dim fileName As String
Dim fileNum As Integer
Dim item As NotesItem
Forall v In db.Views
Set mainDoc = v.GetFirstDocument
fileNum% = Freefile()
fileName$ = "C:\AllViewsData\" & v.name & ".txt"
Open FileName$ For Append As fileNum%
Write #fileNum% , "////// VIEW NAME:" & v.name & "////////////"
Set mainDoc = v.GetFirstDocument
While Not ( mainDoc Is Nothing )
Forall i In mainDoc.Items
ss = ss & " " & i.Name
End Forall
Write #fileNum% , ss
Set mainDoc = v.GetNextDocument( mainDoc )
Wend
Close fileNum%
End Forall
End Sub
I designed sql(relational) table for each notesForms. I was trying to retrieve data using notesForm and store that in corresponding table but I could not do that :(
Any help is highly appreciated.
Form describes the schema / UI for your data. What you actually need to export / query are the Lotus Notes documents in the database, not the forms.
As for views, these are simply a "window" on your data, and again don't need to be explicitly exported. There's a very similar post to yours here, and my answer covers the difference between data, forms and views:
How to get the underlying view of a form using lotusscript

Resources