For workaround, see below.
Our Scenario:
A List of Docments are getting updated in a for-Loop, e.g. by ComuteWithForm(). Other Documents must be updated if some fields are being changed, e.g. “readers” must be spreaded to the response documents. Our goal is (due to performance) to update the responses only if nesessary, that means we need to compare fields before and after an Update to a NotesDocument (unsaved at this point).
The problem is that a second instance of a NotesDocument (retrieved by getDocumentbyUNID->should contain the previous state of the unsaved document) not only has the same field values as the unsaved first instance, further adding fields to the first Document adds those fields to the second instance as well.-
Example:
//get the 1st selected document in View
set doc = db.UnprocessedDocuments.GetFirstDocument
//Add Field “TESTFIELD” with value “1” to the NotesDocument (not saved yet)
doc.TESTFIELD = “1”
//get the saved copy for compare
set savedDoc = db.getDocumentbyUNID(doc.UniversalID)
Print savedDoc.TESTFIELD(0)
→ this prints “1”, should be “”, since the saved Doc doeasn’t have this item!
→ no matter if the savedDoc is bound before or after TESTFIELD is added to the in-memory/unsaved document “doc”
doc.Testfield2 = “2”
print savedDoc.TestField2(0)
→ this prints “2”, should be “”!
How else can I compare fields of the unsaved backend document with the altered, unsaved instance of the document (except storing the field values in variables before altering the first instance)?
Workaround:
A trick is to use a special view, from which the saved / unaltered copy can be retrieved by View.GetDocumentbyKey(key, True). The key can be e.g. the UNID or NoteID of the document.
This works in QuerySave and WebquerySave as well, at the cost of an extra view in the database.