Subscription by Category - Code

Posted on 2002-04-04
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

756 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