Reputation: 403
I try saving my document the document got saved without any error but the response document is no where to be found. The response document is a list of document in a datatable selected using a checkbox. The below code is placed on the onchange event of the checkbox:
<xp:checkBox id="checkBox1" value="#{vProductListCollection}">
<xp:eventHandler event="onchange" submit="true" refreshMode="norefresh"
id="eventHandler1">
<xp:this.action><![CDATA[#{javascript:
var colTitle = vProductListCollection.getColumnValue("Title");
var prodTitle = viewScope.get("title");
var docId = viewScope.get("id");
var selDocID = vProductListCollection.getUniversalID();
if(docId.contains(selDocID )) {
prodTitle.remove(colTitle );
docId.remove(selDocID );
} else {
prodTitle.add(colTitle );
docId.add(selDocID );
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:checkBox>
Postopen event:
var titleList = new java.util.ArrayList();
ViewScope.put('title', titleList );
var idList = new java.util.ArrayList();
viewScope.put('id', idList );
On my submit botton (to create response doc for NEW main document) i have:
currentDocument.save()
var TL:java.util.ArrayList = viewScope.get("title");
var Id:java.util.ArrayList=viewScope.get("id");
for(var x=0;x<Id.size();x++){
var doc=database.getDocumentByUNID(Id.get(x));
var resdoc:NotesDocument=doc.copyToDatabase(database);
resdoc.makeResponse(currentDocument.getDocument());
resdoc.save();
}
When i submit my main document got saved but without the responce document, and hint?
Upvotes: 1
Views: 1127
Reputation: 30970
copyToDatabase()
doesn't work sometimes so well. The workaround and best practice is to create a new document and copy all items.
Your code could look like this then:
for(var x=0;x<Id.size();x++){
var doc=database.getDocumentByUNID(Id.get(x));
var resdoc:NotesDocument=database.createDocument();
doc.copyAllItems(resdoc, false);
resdoc.makeResponse(currentDocument.getDocument());
resdoc.save();
}
Update:
I found the reason for not creating response documents: your Postopen(?) event code never gets executed as SSJS. It would throw an error as is has a capital letter "V" in "ViewScope.put('title'...". Because the code gets never executed viewScope "Id" remains empty and therefore the for-loop which would create response documents is never entered.
Put the correct code in beforePageLoad event and it will work.
<xp:this.beforePageLoad><![CDATA[#{javascript:
var titleList = new java.util.ArrayList();
viewScope.put('title', titleList );
var idList = new java.util.ArrayList();
viewScope.put('id', idList );}]]>
</xp:this.beforePageLoad>
Upvotes: 1