File Download Control - xpages

Is it possible to access the currently deleted file of a <xp:fileDownload> control?
Im am searching for something like onDelete or beforeDelete event?
I need this, because I have to save the deleted files in a history log.
Thanks in advance
UPDATE (useful answer of a similar problem):
https://stackoverflow.com/a/11941037/4717072

sorry this is all from memory, i may update the answer tomorrow with any corrections (not near my computer at the moment)
instead of thinking in terms of the download control, maybe you could think in terms on the domino document data source.
when you click the delete link of the file download control, it does not immediately delete the attachment but it marks the attachment 'to be deleted' the next time the document is saved.
this information is managed within the domino document data source and not within the control.
there is an 'attachment list' for each attachment field which keeps track of the current state of each attachment in that field. example states are 'in document' 'pending upload' 'deleted'
so maybe in a before save / after save event of the document you could check the attachment list and the state of each attachment and figure out which ones were deleted
the appropriate method to get the attachmentlist is something like
doc.getAttachmentList('yourfield')

Related

Lotus Notes documents - Gets corrupt & Field Info Tab is empty

I have a notes database and recently we are having an issue across random documents. Users gets error "The linked document cannot be found in the view" when they try to open a document from a view. I am not sure how to reproduce this issue.
I tried the below options to reproduce it, but no luck:
Attaching a document link to one of the Rich text field and deleting the link's target.
Attaching a file as a link and deleting the file in the target.
I am not seeing any pattern with the documents having the issue. The documents accessed few days ago, which was not accessed for more than 2 years also becomes corrupt like this.
Other details:
The Field info tab in Document properties dialog box is empty
There is no scheduled agent running overnight affecting this documents
No change was done to the database recently
We recently migrated to Notes 11.0 from 9.0
Since we have a daily backup of the database, we restore the document from one of the restored copy in which it was working fine.
A guess: did you try re-indexing the view? Shift-F9?
It could also be in the form, or even the view.
What if ...
you open the same document from a different view?
you remove some, many or all fields from the form, do you still see the error?
I think those documents have actually been deleted, and two things make me think that:
You say in a comment that rebuilding the view makes the documents disappear. I'd expect this only if the documents no longer exist.
I have in the past had LotusScript code doing view lookups which produced documents that I knew to be deleted, but the NotesDocument.IsDeleted property was False and the NotesDocument.Items property was Empty (i.e. no fields in the document). This is consistent with your saying the Field info tab is empty.
I'd check if any user action or code could delete documents. You say there are no scheduled agents, but maybe some user action could run code which deletes documents, or some users with the Delete privilege in the database ACL could be directly deleting documents using the Delete key on the keyboard.
Also check the database properties -> Info tab -> User Detail. This should show if there are recent deletions, but the record is probably limited to the last week or less.

Create a session where DOCUMENT can't be edited until a session done

Follow up by my Question here about doing a version tracking and show responses I have another question. I have a PC Specification view. What I want to do is, when I want to do a Specification for all PC, I will create something like a draft for all PC as a new document. After it all save, the draft/new document with edited will be as updated data and show as the current document, and old document data will be stored as archived.
Is there any function for me to do that? Should I create a "form" page named "ARCHIVED" and save all document there for review? OR is there any session function or anything?
I have found this link example archive with delete but it needs to create a new database. Do I need to create a new database for the archive?
Any help will be appreciated. Thanks!
You could create a status field. for example "DocumentStatus" as text or radio and set it to wathever you like. I prefer alias values like
"0" -> draft
"10" -> active document
"20" -> archived
Then you are able to filter in views with SELECT .... & DocumentStatus="20" to only show the archived documents

Why cannot I delete a Lotus Notes document?

in my Lotus Notes agent, I temporarily created some documents using a new form (with a richtext field in the form), and in the end of the code, I have "Call TempDoc.Remove(True)", when the program execute this line of code, I got error "Notes error: No documents were deleted", then I commented out this code to let the document saved in the current database, so I manually delete those documents created by my program by click Delete key, but I got the same error "No documents were deleted", I have Manager access with delete option in the database ACL,
Does anybody know why I got that error?
By the way, if I created a new document by using the default form which is not the form used in my program above, then I can delete it.
So, the question may be: what kinds of documents created in the notes database can NOT be deleted by a id with Manager and Delete option?
The NotesDocument.Remove(true) method may be trying to do a "soft deletion", but the database may not be properly set up for soft deletes. If you don't care about soft deletes, then try the NotesDatabase.RemovePermanently(true) method instead.

I Need to prevent saved conflict in xpage

Scenario :- I opened the same document in different browsers(users). One user modified and saved the document. another user also modifying the same document which creates saved conflicts. for this I googled and found the link and tried.
http://dontpanic82.blogspot.in/2010/01/xpages-custom-control-that-can-help.html
(Thanks to Mr Tommy).
I included this custom control in another custom control(Form) at the end of Cc.
I am getting currentDocument not found in before render response event. I have my data source name document which is defined for full page not for panel.
Document handle is not getting in Before render response event?
Please help to me to solve this. or is there any other way to prevent saved conflicts?
Have a look at the concurrencyMode property of the document datasource.
You can for instance set it to fail in order for the document save to stop (fail) if a save conflict occurs. If you have (or add) a message control to your xpage, a save conflict error message will then appear.
If you isn't building for XPinc you could use my Document locker project on openntf.org
Document Locker on openntf.org
It works like this, when a user opens a document a< lock is added to an application scope bean. And when the user exits the document this lock is removed. if another user tried to enter the document at the same time they will be redirected to readmode.
Also, check the section in Mastering XPages 2nd Edition about document locking. That gives thorough examples for enabling the in-built Domino document locking.

Adding logging in Lotus Notes form

I want to add logging capabilities in my Lotus Notes application. Basically I want to be able to log who make the change, when the change is made, and what field(s) is/are changed in a document. What is the best way to do this? I am thinking to also add this at the end of each document so the user knows who make the changes.
OpenNTF has several tools for this purpose that you could use, including Open Audit and Audit Manager.
I've done this before using LotusScript. It's a bit of a pain, but the basic idea is to:
Create an array or new document object within the QueryOpen event, and store the values for all the items in the current document.
In your QuerySave event, compare the values of the current document to the in-memory copy you made, and then log any differences.
You can create a field on the form to write these changes to, and just append to it each time.
Watch out for other event handlers that make changes everytime the document opens, though. You may need to copy original values in the PostOpen event, for example, if you change some fields in the QueryOpen event each time the doc opens, otherwise you'd get false change logs.
Hope this helps!
A "brute force" approach can also work. Every time a document is saved, create a copy of that version to a (separate) database. This will build an audit trail of the documents. The documents can be compared to extract the changes.
There is quite some overhead in this approach, but in my experience it has been worth it. The implementation is simple and all changes are captured without affecting the actual document. All information that is needed is captured and available for (offline) processing.

Resources