Currently I am working on a function where users can create a profile for a newsletter. In the profile the user can specify a search query and some options.
It all begins with a simple View Action button:
The button will check if for the current user already a profile document exists, if so the document will be opened in edit mode, otherwise the form will be opened (the client requested to make all profiles public…)
varUser:=@Name([Abbreviate];@UserName);
@If(
@IsError(@DbLookup(“”:”NoCache”;””;”v-userprofiles”;varUser;”Tx_DocID”));
@Do(
@Command([Compose];”F-PU”)
);
@Do(
@Command([OpenView];”v-userprofiles”;varUser);
@Command([OpenDocument];”1″)
)
)
The form itself is pretty plain and simple. The user can add more criteria to the search query via ‘AND’ or ‘OR’ options. Default we search on only one type of document.
While specifying the criteria, the user sees what he/she is adding to the query:
The code behind the ‘ADD’ button is this:
varForm:= “Document”;
varField:=Tx_Fields;
varValues:=@Implode(“\”” + Tx_Values + “\”” ;”:”);
@If(Tx_Option=”AND”;
@Do(
varConstructor:= ” & ” + varField + ” = ” + varValues;
@SetField( “Tx_Query” ; Tx_Query + varConstructor );
@SetField( “Tx_LastValue” ; varConstructor )
);
@Do(
@If(@Left(@GetField( “Tx_LastValue” );”)”)=””;
@Do(
varPrevValue:= @Right(@GetField( “Tx_LastValue” );”& “);
varConstructor:= ” & ( ” + varPrevValue + ” | ” + varField + ” = ” + varValues + ” )”
);
@Do(
varPrevValue:= @LeftBack(@GetField( “Tx_LastValue” );”)”);
varConstructor:= varPrevValue + ” | ” + varField + ” = ” + varValues + ” )”
));
varNewQuery:= @ReplaceSubstring( Tx_Query; Tx_LastValue ; varConstructor );
@SetField( “Tx_Query” ; varNewQuery );
@SetField( “Tx_LastValue” ; varConstructor )
));
@SetField( “Tx_Fields” ; “”);
@SetField( “Tx_Values” ; “”);
@SetField( “Tx_Options” ; “”)
I also added a button so the user can check if the specified query results in any usefull document collection. The code behind this button is:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
searchFormula$ = uidoc.FieldGetText( “Tx_Query” )
Dim collection As NotesDocumentCollection
Set collection = db.Search(searchFormula$, Nothing, 0)
numDocs% = collection.count
If numDocs% = 0 Then
Messagebox “There are no matching documents” , , “Search Result”
Exit Sub
Else
answer% = Messagebox ( (numDocs% & ” document(s) match this query. “), MB_OKCANCEL + MB_ICONQUESTION, “Search Result”)
End If
End Sub
Because the Newsletter function has to run on a scheduled basis I added some additional options:
- How often a Newsletter should be sent
- The number of document links in the Notes Newsletter
- How old corresponding documents may be
Note: in the timestamp you can add for a search Notes uses the modified date, so this is the date the document has been modified (nice if you working on a test environment with a copy so all the documents ARE modified). You can also add this option as criteria in your search formula ofcourse.
On the bottom of the form I added a button where the user can instantly receive a Notes Newsletter with everything he/she has specified. The code for the button is:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim doc As NotesDocument
Set doc = uidoc.Document
searchFormula$ = uidoc.FieldGetText( “Tx_Query” )
maxListSize = uidoc.FieldGetText( “Tx_QueryMax” )
daysAdjust = doc.Tx_QueryDays(0)
Dim dateTime As New NotesDateTime( Now )
Call dateTime.AdjustDay( -daysAdjust )
Dim collection As NotesDocumentCollection
Set collection = db.Search(searchFormula$, dateTime, Cint(maxListSize))
numDocs% = collection.count
If numDocs% = 0 Then
Messagebox “There are no matching documents” , , “Search Result”
Exit Sub
Else
answer% = Messagebox ( (numDocs% & ” document(s) found. Creating a Newsletter…”), MB_OKCANCEL + MB_ICONQUESTION, “Search Result”)
Dim newsletter As NotesNewsletter
Set newsletter = New NotesNewsletter( collection )
newsletter.DoSubject = True
newsletter.SubjectItemName = “Tx_Title”
Dim newsletterdoc As NotesDocument
Set newsletterdoc = newsletter.FormatMsgWithDoclinks( db )
newsletterdoc.Form = “Memo”
newsletterdoc.Subject = “Business Intelligence Newsletter – Your results”
Call newsletterdoc.Send( False, uidoc.FieldGetText( “Tx_UserName” ))
End If
End Sub
Some parts of the code above I will re-use in the scheduled agent that sends out the Newsletters on a scheduled base.
Wrap-up: a simple handy function that might save you creating some additional views…
Hi there,
I have a question: how do you (or how can you) create a newsletter on Lotus?
Thanks for youru feedback,
Marion
Hi I was very interested in this post as I am trying to implement similar functions within one of our applications, do you have a sample database for download ?