Subscription by Category - Code

Posted on 2002-04-04
Medium Priority
Last Modified: 2013-12-18
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?
Question by:blyons48
LVL 10

Expert Comment

ID: 6918949
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...
LVL 13

Expert Comment

ID: 6918996
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.
LVL 24

Accepted Solution

HemanthaKumar earned 400 total points
ID: 6921221
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] ); "")



Author Comment

ID: 7222401
Excellent, thanks.
LVL 24

Expert Comment

ID: 7222502
Thank you for A Grade

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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.

Join & Write a Comment

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question