1
votes

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?

1
You need to put the code into more context. The idList, title variables in your postopen are coming from where? Create a minimal XPages with the problem and provide the sourcestwissel
with the idList am just creating an Array, that will store the item from the selected documentsimon peter
TitleList goes nowhere. You added title to the scope not titleliststwissel
i have edited it, thankssimon peter
@stwissel, do u have any idea why my response document is not been saved along with the main document?simon peter

1 Answers

1
votes

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>