I have a form with an embedded folder with the columns Report Number, Author Name and Report Title. The view is sorted by Report Number. My client has requested for a button that sends out an email to each Author with their related Report numbers and titles, like a reminder to each specific author of what they have written. There is no need to include a document link.
In other words, I need a button that gets first author name in the view, loops through all the documents in the view, finds the docuemnts which have the same authorname and append the Report Number and Report Title, send out the mail, and then loops through the view again for all unique Author Names listed.
I’ve only thought of the first run :
doc = view.getfirstdocument()
strName = doc.AuthorName
while not doc is nothing
if doc.AuthorName = strName
Append Report Num and Report Title
end if
doc = view.getnextdocument(doc)
wend
send mail to AuthorName
I need another loop which loops through each username but what conditions can I set? Bear in mind the reminder may need to be sent out more than once so a flag in the document will need to have its value changed all the time. Is this a problem? Is his the ‘right’ way to achieve the objectives?Is there another simpler way to do this?
Thanks in advance
Subject: Need to loop through a view and send each unique user listed their related documents
Ideally you only want to loop throught the documents once.
Easiest way would be to create a view sorted by author, loop through the documents building up an email as you go, then when the author changes (store the last author in a string and compare with author of current doc) fire off the email and generate a new blank email ready to append to.
If creating a new view isn’t an option then you could use a List variable indexed by author name to hold the text of the emails to send. Then step through the view appending to the relevant author’s element in the list e.g. myList(author)=myList(author)+ Title and Report Num. Then when you get to the bottom of the view, use forall to step through the list and send the emails.
Don’t forget to include error handling just in case you attempt to send an email to someone who has left the company and no longer exists in the NAB.
Updating all of the documents with multiple reminder sent flags isn’t that desireable if the database is heavily used, has a large number of docs or replicates to remote users. But sometimes is a necessary evil. There are alternatives (e.g. use of folders, or profile documents that hold lists of reminders sent) but nothing is ideal.
HTH - Rufus.
Subject: RE: Need to loop through a view and send each unique user listed their related documents
I’ve managed to get it working fine! Thank you very much for your responses. the list works very well. I’m trying to save all the sent messages in the client’s mailbox now. I’ve tried setting the .savemessageonsend property to true but this only saves it to the current database. How do I save it to the client’s? I’m guessing it’s because I set the document to
Set maildoc = New NotesDocument(db)
and db is the currentdatabase. How do I set db to be the client’s mailbox without hardcoding it?
Subject: Need to loop through a view and send each unique user listed their related documents
You could use a database search to find all relevant docs. You could get a unique list of Authors from the Authors Column in the view:
Authors=Evaluate(|@Unique(@DbColumn(info for your column…))|
Then for each Author:
for i=1 to Ubound(Authors)
Author=Authors(i)
Get a documentCollection of docs for that author
Set collection = db.Search(|Form =“Your Form” & Author=Author|,Nothing,0)
For each doc in the dc:
For j=1 to dc.count
Set doc=dc.getNthDocument(j)
Get the relevent field values from here
Hope this helps,
Niall.
Subject: RE: Need to loop through a view and send each unique user listed their related documents
Thanks for your quick response. I’m trying to get Evaluate to work now. However, I keep getting a type mismatch at the “Author: for i=1 to Ubound(Authors)” part when I’m debugging. Do I need to convert the variant into an array? How do I go about it?
I’ve initialised Authors as variant.
Subject: RE: Need to loop through a view and send each unique user listed their related documents
Sorry My Mistake, Authors is base 0, should be from i=0 to Ubound(Authors)
Turn on the LS debugger and make sure that the evaluate is returning values. If not, you might want to check the @DbColumn formula…