Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to delete documents from view

Posted on 2009-04-30
Medium Priority
Last Modified: 2013-12-18
I'm not a Lotus Notes expert, so forgive any misuse of terminology
I'm hoping this isnt too complicated, but I've oodles of question points available to spend on it if it does...

I have a domino database that receives messages daily from lots of different sources, and an agent that identified the ones Im looking for, and puts them into a view.
I want to scan the view, keep the latest document from each source (its a unique document subject), and delete all older copies.

I've written some code (Perl) that uses the Notes.NotesSession object to:
Open the view
Create a viewnavigator
and loop through each document via ViewEntry ->GetNextDocument, so I can extract all the details I need.

I intend to compare (for each document subject) the posted date in order to determine the one I need to keep, and mark the 'other' one for deletion.
This could be either from either the current viewentry I have, or the one I've stored previously.

I've got it happily printing out what its doing, what records its looking at, and identifying the correct ones to delete, but haven't got it yet actually doing it

I dont have any problems with the coding, but I dont understand the Domino COM implementation well enough to know if:

1. is this an acceptable way to do it?
2. Is there a way to order the documents in the viewnavigator so I get the newly posted ones first?
3. If I need to delete a previously 'stored' document reference - what would I need to store in order to retrieve it, and do the deletions affect the viewnavigator.

any advice or code snippets appreciated - I dont mind what language they come in!

hope this makes sense....
Question by:BobMc
  • 4
  • 2
  • 2
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24270156
Re your questions:
1) Id' say no, it is not; why don't you use Domino the way it is supposed to be used? You can program that function in a database agent, and it'll be activated automatically by the server. No need for external applications whatsoever.
2) Yes, you have to reorder the view itself: for example, the first column could contain the function @Created; then, set it to decreasing order
3) I think I don't understand... what if your first column were the subject, and the second column the creation date?

> any advice or code snippets appreciated - I dont mind what language they come in!
I might have some advice for you, shall I continue in Dutch or French...?    ;-))
LVL 22

Expert Comment

ID: 24270333
It's acceptable, why not (unless you can access Domino database design, then I agree with Sjef).

If you don't have access to domino db design, then you'll have to find max date/time the doc is modified, that's no problem...

Why don't you post the code you have so far?

Author Comment

ID: 24279199
Thanks for the responses. Yes, I understand this would be better / easier done within Domino, but I don't have that luxury in this case.

I've posted the interesting bit of the code I have so far.
I'm keeping track of the newest document by subject in a hash, so it doesnt matter what order I search the documents. I either need to delete the current document, or the one I already referenced in the hash.
I was sort of hoping that I could save a unique ID for each document, and delete it with that, but Im unsure how to proceed

I'll all ears if theres a better / different approach to doing this via COM that I should consider.

$NotesSession = Win32::OLE->new('Notes.NotesSession')
                or die "Cannot start Lotus Notes Session object.\n";
$NotesDB = $NotesSession->GetDatabase($servername, $databasename)
               or die ("Can't open database $databasename\n");
               or die ("Can't open view $viewname\n");
my $doccount=$NotesViewNav->{Count};
print "There are $doccount documents in view $viewname to process\n";
my $docindex=0;     ## Current doc position in ViewNav - dont know if this is useful
my %LatestDocs=();  ## Capture the details of the latest posted
                    ## document for each subject
while (defined ($NotesViewEntry)) {
  $NotesDocument = $NotesViewEntry->Document;
  ## extract all the fields at once
  my $doccollection = $NotesDocument->{Items};
  ## convert to perl hash ref
  my $docitems=&CollectionToHash($doccollection);
  ## We assume that the subject will never change, and is unique per server
  ## So we need to check that within the view, this is the latest (or only)
  ## document (subject) for this server.
  ## If the current subject is not in the hash, so its the first we've found for
  ## this server, and we store it
  ## If the current subject is already in the hash, and the current is older,
  ## we delete it
  ## If the current subject is already in the hash, and the current is newer,
  ## we delete the stored one, and store the current one
  ## Need to ensure we extract the next document before we delete anything.
  ## Subject is "title string : server name". Dont need title bit
  my ($subject) = ($docitems-> {Subject} =~ /:(.*)/);
  my $posteddate= $docitems->{PostedDate};
  print "Doc[ $docindex / $doccount ]:  Subject $subject\t\tPosted at $posteddate\n";
  ## Convert date to numeric for comparison (tz excepting)
  my $eposteddate=DateStringToEpoch($posteddate);
  ## Do we already have one of these?
  if (exists($LatestDocs{$subject})) {
    ## Already got one - is it newer that the current one?
    if ($LatestDocs{$subject} >= $eposteddate) {
      ## Stored doc is not older -> keep stored one and delete current
      print "Delete current doc for $subject, posted at $posteddate\n";
    } else {
      ## current doc is newer
      ## so delete stored doc, and save current details
      print "Replace stored doc for $subject posted at "
      print "With current doc for $subject posted at $posteddate\n";
  } else {
    ## new subject => this one is newest for now, so store it
    print "New - store current doc for $subject \n";
  last unless $docindex < $debugdoccount;

Open in new window

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 46

Accepted Solution

Sjef Bosman earned 500 total points
ID: 24279755
Every document has a unique key, and an almost unique key (only unique per replica of a database). Use doc.UniversalID.
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24279786
And to move back to a document, use view.GetDocumentByUnid()
LVL 22

Assisted Solution

mbonaci earned 500 total points
ID: 24293472
GetDocumentByUnid is member of NotesDatabase, not NotesView (GetDocumentByKey).

So, to get the document use:
Set curDoc = db.getDocumentByUNID( "earlierSavedUnid" )

To delete the doc use:
Call curDoc.RemovePermanently

To remove doc only from the view (and leave it in a db) you'll have to figure out which flag is used to show documents in that view (analyze either Agent that puts docs in a view or View selection formula). Then use:
Call curDoc.RemoveItem( "itemName" )

to remove flag field.

Author Comment

ID: 24334861
thanks for the help guys, I've managed to trash several replicas now, so I know I'm on the right track :)
LVL 46

Expert Comment

by:Sjef Bosman
ID: 24335520

Very good!!

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

580 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