Subscription by Category - Code

I am looking to establish a subscription function in a Lotus Notes database.  There is a dialog-list field named "Category" in the "Main" Form, and this field can take on values of say Apples, Bananas, Cherries, etc.  We'd like to allow the user to subscribe/unsubscribe to any (one or multiple) of these catgegories, so that when he is subscribed to the Apples category, anytime a document having this category is saved (either new or updated doc), all the subscribed users would get an automatic email.

Does anyone know if there is some canned code available that has such a subscribe function?
Who is Participating?
HemanthaKumarConnect With a Mentor Commented:
Let me give you a simple approach.

Let us say you have a field called 'Category' and two buttons namely, Subcribe and Unsubscribe

Subscribe Will contain this code on CLick event

Sub Click(Source As Button)
     Call Subscription( "Subscribe" )
End Sub

Similarly for Unsubscribe
Sub Click(Source As Button)
     Call Subscription( "UnSubscribe" )
End Sub

Here is the main function "Subscription" which will be declared as global.

Function Subscription( Flag As String )
     Dim ws As New NotesUIWorkspace
     Dim note As NotesDocument
     Set note = ws.CurrentDocument.Document
     Dim s As New NotesSession
     Dim db As NotesDatabase
     Dim pDoc As NotesDocument     ' Parameter document
     Set db = s.CurrentDatabase
     Set pDoc = db.GetProfileDocument( "ParameterDoc")    
     subscriber = s.UserName
     Forall opts In note.Category
          If opts = "" Then Exit Function
          If pdoc.HasItem(opts) Then
               Set item = pdoc.GetFirstItem(opts)
               Set item = pdoc.ReplaceItemValue(opts, Null)
          End If
          Select Case Ucase(Flag)
          Case "SUBSCRIBE":
               If Not item.Contains(subscriber) Then
                    Call item.AppendToTextList(subscriber)
               End If
          Case "UNSUBSCRIBE":
               count = 0
               Forall v In item.values
                    Redim Preserve strarr(count) As String
                    If v <> subscriber Then
                         strarr(count) = v
                         count = count + 1
                    End If                    
               End Forall
               Set item = pdoc.replaceItemValue(item.Name, strarr)
          End Select
     End Forall
     item.IsNames = True
     Call pdoc.Save(False,False)
End Function

The next part would be for mailing. I am assuming that you want to just notify user that document has been changed/saved by someone. So create a computefordisplay field with following formula in it.

SendTo := @GetProfileField( "ParameterDoc"; Category);
@if( SendTo = ""; @Return(0); "");
@If(@IsDocBeingSaved; @MailSend( SendTo ; "" ;""; "Following document has been changed" ; "Click on the doc link for more info, " ;"" ; [IncludeDoclink] ); "")


Normally are notifications sent daily, but if you prefer, change the schedule from OnceDaily to DocumentsBeenCreatedOrModified. Agent gets in both cases the correct collection of modified documents.
Best example is the Lotus TeamRoom template and its Interests profiles. Look for SendNewsletters agent.

I know that this is too powerful for your needs, but on other hand you ask for specific Category settings. I have tried to help one time ago to develop a simple booking concept to one questioner. Believe or not, this is soon a never ending story, you can not take from another concept, you have to develop it on your oven and drive it in your direction. Sorry...
Did it once....

I used a separate subscription database. This allowed me to use only one subscription database for numerous other databases.
Database owners could (with help of Admin) introduce new topics and link them to certain mail groups.
For every user, I recorded the topics that he / she is subscribed to. selectable topics were retrieved from the owner-defined list and presented as checkboxes.
I recorded subscriptions on a normal documents, not profile documents, to be able to collect all subscriptions containing a specific topic from a view. Documents would be protected by author / reader names field to allow only the user and a specific userrole (for server / agents / db owner and/or admin).

Documents would appear in two views:

A: sorted by username (to be able to find the subscriptions for every user),

B: sorted by topic (needed to collect all users, subscribed to the same topic)

An agent, triggered by document changes, would, for each topic, collect usernames from view B and store the result in a mailgroup-document in the NAB. Mail can easily be sent (automatically) to such pre-defined groups.

After that I fine-tuned the system in several phases. The most important and easy to implement was the addition of several sub-groups. Due to the amount of users I had to define additional groups for each topic, e.g. usernames A-F, G-L, M-S, T-Z. These groups were held in the original "main" group to which the mail was send.

Other changes made it possible to update only the additions / deletions to groups. I would not recommend to try to implement that right now. Could cost you an awfull lot of additional time and might cause a lot of errors / discrepancies.
blyons48Author Commented:
Excellent, thanks.
Thank you for A Grade
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.