Reputation: 1382
I am looking to implement a "Save as new" button. This would essentially take an existing document and create a new copy of the document with all of the existing fields. This would need to be implemented from a document and not a viewPanel.
Upvotes: 0
Views: 162
Reputation: 146
I have a "services" feature in my CMS that allows the author to create a duplicate of the "service" with the following SSJS:
var service = {
...
duplicate : function(thisDoc:NotesXspDocument) {
try {
var newDoc:NotesDocument = database.createDocument();
thisDoc.getDocument().copyAllItems(newDoc, true);
var newId = newDoc.getItemValueString("id") + "-" + session.evaluate("@Unique").elementAt(0) + "-DUPLICATE";
newDoc.replaceItemValue("id", newId);
newDoc.save(true);
context.redirectToPage("/service.xsp?id=" + newId + "&");
} catch(e) {
print(database.getTitle() + " SSJS Error for service.duplicate()");
print(e.toString());
}
}
}
Now, I read the IDs in my dataSources, which is why I'm passing through the newId value. If you're using the out-of-the-box dataSource setup, you'll want to change that to getUniversalID() and set the URL Parameters to "?action=openDocument&documentId=".
[edit]- Here is the script that will work for a standard data source
var newDoc:NotesDocument = database.createDocument();
currentDocument.getDocument().copyAllItems(newDoc, true);
newDoc.save(true);
var newId = newDoc.getUniversalID();
context.redirectToPage("/entry.xsp/%24%24OpenDominoDocument.xsp? documentId="+@Text(newId)+"&action=editDocument");
[edit] (Chris Toohey): I changed "document1" to "currentDocument" to better support the relative local/current NotesDocument dataSource (as someone could change the default dataSource name from "document1" and the suggested edited code wouldn't work).
Upvotes: 3
Reputation: 1356
Not sure if this would work under XPages, but if the document contains a '$VerOpt' notesItem (field name) with a valid setting in it (eg: "2") the database may create a new copy for you. You will have to arrange to set/clear the value as needed. If you wish to create the 'new version' on every save, the form has a default properties has a setting you can set. Search for this reserved fieldname for details.
Upvotes: 0
Reputation: 15739
NotesDatabase.createDocument()
and NotesDocument.copyAllItems(destDoc)
should provide the functionality (or the corresponding Java equivalents). It's better performing than NotesDocument.copyToDatabase()
Upvotes: 2
Reputation: 911
How about something like this: http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllFlatWeb/ad18d9bdca1141b1852576e8004ca5a1?OpenDocument
Upvotes: 0