I have a repeat control which displays documents in a particular view. For each document (row of data) a user can edit and save these items in-line. I have additional button which marks a single document as default and this is visible only in Edit Mode, before it marks the current document as default, it goes through all the other documents and un-marks them from being default. This mark as default works the first time, but when I try it again (second time), it creates replication conflicts.
The edit button just changes the mode to edit mode.
Save does the following (partial refresh):
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="deliveryDocument"></xp:saveDocument>
<xp:changeDocumentMode mode="readOnly"
var="deliveryDocument">
</xp:changeDocumentMode>
</xp:actionGroup>
</xp:this.action>
Set default does the following (full refresh):
<xp:this.action>
<xp:actionGroup>
<xp:executeScript
script="#{javascript:markAsDefault(deliveryDocument);}">
</xp:executeScript>
<xp:saveDocument var="deliveryDocument"></xp:saveDocument>
<xp:changeDocumentMode mode="readOnly"
var="deliveryDocument">
</xp:changeDocumentMode>
</xp:actionGroup>
</xp:this.action>
markAsDefault first of all goes through all existing delivery documents and sets isDefault to be blank (except the current document) and then sets the isDefault value for the current document (it doesn't save the back-end document and the loop does doc.recycle()).
Any help would be appreciated.
Update:
function markAsDefault(deliveryDoc) {
try {
var db:NotesDatabase = deliveryDoc.getParentDatabase();
var vwDeliveryAddress:NotesView = db.getView("viewName");
var dc:NotesDocumentCollection = vwDeliveryAddress.getAllDocumentsByKey(deliveryDoc.getItemValueString("fldID"), true);
var strUniversalID:String;
strUniversalID = deliveryDoc.getDocument().getUniversalID();
if (dc.getCount() > 0) {
var doc:NotesDocument = dc.getFirstDocument()
var nextDoc:NotesDocument;
// mark all other docs as not default
while (doc != null) {
nextDoc = dc.getNextDocument();
if (doc.getUniversalID() != strUniversalID) {
doc.replaceItemValue("isDefault", "");
doc.save();
doc.recycle();
}
doc = nextDoc;
}
}
deliveryDoc.replaceItemValue("isDefault", "Yes");
} catch (e) {
log.logError(e.toString(), SEVERITY_HIGH, e.toString(), null, "website.nsf", "markAsDefault()", null, null);
}
}