I have two documents; document1 allows read/write, but document2 is readonly.
var document1:NotesView = database.getView("viewDoc1");
var document2:NotesView = database.getView("viewDoc2");
//var copiedDoc:NotesDocument=document2.CopyToDatabase(document1);
docEv:NotesDocument = document1.getDocumentByKey("userName");
if(docEv!=""){...}else{...};
beforePageLoad
Before page is rendered, I want to be able copy all data in the readonly document and save it into the read/write document and also check if documents already exist in the read/write, in which case don't copy.
Your help will be appreciated.
This line of your code makes no sense:
var copiedDoc:NotesDocument=document2.CopyToDatabase(document1)
First of all, you said that you want to copy document2 into document1, but you appear to be trying to copy it into a new, third NotesDocument called copiedDoc.
But more importantly, you're passing document1 as the argument into the CopyToDatabase method, but that method takes a NotesDatbase argument, not a NotesDocument argument!
You may want to look at the CopyAllItems method instead.
Related
Is there a way to restore a deleted document that is located in the trash? All I know is the #UndeleteDocument formula.
Use evaluate to execute #UndeleteDocument on a document from a view of type
"Shared, contains deleted documents"
var viewTrash:NotesView = database.getView("trash");
var docToRestore:NotesDocument = viewTrash.getFirstDocument();
var eval = session.evaluate("#UndeleteDocument", docToRestore);
This example undeletes the first document from view "trash" which has to be of type "Shared, contains deleted documents".
There is no Java (nor LotusScript) method for undeleting a document. So, evaluate seems to be the appropriate way to handle this.
I have one page that does a NotesDatabase search and of course returns a collection. I am storing that collection in a sessionScope variable and calling a page where I what ti display the results.
if ( collection1.getCount() == 0)
{
displayErrorMsg("Your search returned zero results. Please try another search.",getClientId("title"), "Zero Results");
}
else
{
sessionScope.put("searchResults",collection1);
var extCont = facesContext.getExternalContext();
extCont.redirect("xp_vwIssueSearchResults.xsp");
}
The page has a data table with the content of the scope variable as it's datasource:
sessionScope.get("searchResults");
When I call this page I get, NotesException: Object has been removed or recycled.
Should I be able to pass a NotesDocumentCollection in a sessionScope variable? I have some thoughts on work arounds but it would sure be nice to pass the NotesDocumentCollection.
You can't keep Notes objects like views, documents, collections for a longer time. In general, you should work with Notes object in a way, that you save the data you're interested in somewhere and recycle (=destroy) the Notes objects right away. The reason is that the Domino server can't save the Notes objects for you between two request because Notes objects aren't serializable (serializable = ability to save objects on disk and restore them back to memory).
In your case, you could save
the search query or
the result values as an Array of Objects (JavaScript) or a List of Maps (Java) or
the documentUniqueIDs of document collection's documents
in your sessionScope variable and use them in your redirected page.
I have a process on the beforePageLoads that executes if it is a newDocument. It grabs a profile docuemnt that contains a number of fields that I need to copy into the XPage that is being loaded. I use the following code:
var iCol:Array = pDoc.getItems()
for(var i=0; i<iCol.length; i++){
var item:NotesItem = iCol[i];
var iName:String = item.getName();
if (#Left(iName, 2) == "AC" ){
iCol[i].copyItemToDocument(doc,"");
}
item.recycle()
} // for loop
where pDoc is the profile document and doc is backend document obtained by var doc = document1.getDocument(). I can then use the copyItemTODocument method and this works real well except I need to refresh the dataSource from the backend document. I can do this from a button and do a partial refresh but that is not an option in a production situation. I have tried various refresh options (suggested in this forum) but none of them get the job done. I can copy the values from the profile document fields to a filed in the datasource but this gets really messy because of data types. I believe my refresh problem is related to updating the doc not document1 in my code. Is there a way to refresh document1 from the backend document?
Does this help ..
http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=84329CA285163DDF852578CB00669143
it hints at two things whcih may be osf use :
"It appears that during the initial PageLoad events the existing data is transferred from the NotesDocument to the NotesXspDocument. Only those fields bound to the NotesXspDocument (on XPage or CC) are transferred. "
and in the comments section:
"Another way of getting data from the XspDocument to the NotesDocument without a save, is to use document1.getDocument(true) which basically re-syncs the data between the two objects.
I don't have time to experiment I'm afraid but it looks like this is along the right lines, espcially the second part.
Doug
My app allows a user to edit data, but during save there are two things that can happen:
If the name of the data stayed the same, just save the object as an edited version. I.e. they are just editing the existing object.
However, if they have changed the name, this should create a new instance and restore the edited data to the original.
Obviously, 1 is the easy case and is working just fine. But I'm conflicted about the best method to handle 2. How best is it to save a modified NSManagedObject as a new row in the DB?
There is no obvious way to just "copy" a NSManagedObject. The most robust way is to simply recreate everything from scratch.
Make sure you have all the changed attributes stored separately (here I am assuming they are in various text fields or that they are unchanged from the existing object). You can make this decision (new instance or not) when your editing view controller is dismissed:
if (![nameTextField.text isEqualToString:object.name]) {
ObjectClass *newObject = [NSEntityDescription
insertNewObjectForEntityForName:#"ObjectClass"
inManagedObjectContext:self.managedObjectContext];
newObject.name = nameTextField.text;
newObject.attribute1 = oldObject.attribute1;
// or
newObject.attribute1 = attribute1TextField.text;
// do this for all attributes
[self.managedObjectContext save:nil];
}
in my symfony application there's a form to fill out and submit with ajax (the user can submit many times).
When the user submits the form, I would like to store the object somewhere (to save in the database later) and I was wondering where is the right place!
can anyone help me??
tnx
Jury D'ambros
The best answer really is saving the object to the database and maybe have a column in that table that flags the object as temporary.
Another approach could be saving the object to the user's attribute holder:
$object = new YourObject();
// deal with the form bind here
// ...
// i is an integer so you may have different attributes
$this->getUser()->setAttribute('ObjectName-'.i, $object);