How to "Not allow document deletion from within a view?"

I have a view that contains “department profile” documents. I’m using the lotusscript “Queryrecalc” view event to intercept deletions, but this event intercepts all refreshes.

OK, so I need to determine if the user pressed the delete key on a document to mark it for deletion. I only allow certain users to do this.

To solve my problem I simply need a way to find out if there are any documents marked for deletion in the view.

Note: I don’t have the authority to change the ACL and there are many users with ACL editor/delete authority that don’t have authority to delete documents in my view which is why I need to figure this out.

Thanks, Paul.

Subject: How to “Not allow document deletion from within a view?”

Hi Paul,

In the

Other → Database Resources → Database Script

you will find a stub declaration for:

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

You can determine using the CurrentView whether the document is being deleted from any of those views and then prevent them from doing so.

However, you should know that a user might be able to delete a document from his/her own private view or even by opening a document in Read mode and pressing the Delete key so this is not really a way to protect documents from deletion (I mean by checking whether the current view is one of those views).

Rather, it might be better to trap the event and check whether the document being deleted uses some particular form or has some other identifying means that either permits its deletion or prevents it.

Subject: How do I trap the event.

Hi Cesar. I wasn’t aware of the Database Resources. Thanks.

However, I don’t understand when the Querydocumentdelete event occurs. I put a message box in the event then turned on debug. I opened my view & pressed delete then F9. My document was deleted, but I never hit the Querydocumentdelete event.

In general when does this event occur?

Thank you!

Paul.

Subject: RE: How do I trap the event.

To prevent deletion, you have to set Continue = False.

Also, I believe that for the changes to Database Script to run, you need to close the database and re-open it (Database Script if I’m not mistaken is examined at the time the database is opened and somehow cached for the remaining time that the database remains opened - I think…)

Lastly (and I’m not sure about this either), have you hit F9 to physically delete the document from the database or is it still simply marked for deletion (in the Trash folder, as it were)?

Subject: RE: How do I trap the event.

Thanks for your help!

Within my view, when I delete and hit F9 the document is permanently deleted. We don’t have soft deletes in this database.

I can intercept all changes to the view, but without knowing if there are any documents marked for deletion this won’t help me.

I will use what I leared from you about Database resources for something, but I don’t think I can make it work for this.

At this point, I’m not sure there’s really an easy way to accomplish what I need unless I can find a way to read the selection margin where the delete “x” shows up.

Thanks, Paul.

Subject: RE: How do I trap the event.

Very odd - I tried this on a database that also does not have soft deletes enabled and this was the only code:

Msgbox "Deleting..."

Continue = False

Exit Sub

As soon as I pressed the delete key after selecting some documents in a view, I received the message box but the document was not deleted.

My idea was that you can add some logic before setting Continue = False (depending on user name, form of document being deleted, etc.) but it should certainly work. For some other class of users, the Continue does not need to be set.

Subject: Success! Thank you Cesar!

Yes, you are right. It is working now.

The 1st time I tried what you told me, I was still hitting my old code. When I closed the database and reopened it works correctly. The “querydeletedocuments” event fires immediately upon pressing the delete key.

This solves my original problem and as you suggested is a far superior method to protect my documents than figuring out what’s marked for deletion!

Thank you.

P.S. I’m an inexperience Domino programmer which is why you may not understand how I could get messed up on the things I get messed up on. Thanks for your patients and support.

Subject: aka “How to determine if documents are marked for deletion?”

I think my 1st title might be confusing.

Subject: RE: aka “How to determine if documents are marked for deletion?”

Ahhh - I had already provided an asnwer by the time I saw this.

Anyway, I don’t think you need to check whether they have been marked for deletion - you can still use the suggestion I made with the QueryDocumentDelete to either allow or prevent deletion.