0
votes

I have 2 buttons, button1 (to create response doc for NEW main document) & button2 (to create response doc for existing main doc) For the first time when I create a new main ‘MyBirthday’ document, and create response, then only 1 response document is created even if I try to create more response documents. This is the time when I hide button1, which saves main document before calling create-responseDoc function.

For second or more entries for response documents, I created button2 which directly calls create-responseDoc function, as my main document is already saved. Clicking on button2 doesn’t affect anything. It doesn’t create responses. BUT, if I close and reopen the document.. this same thing works fine. I am finding it difficult to understand what is actually happening behind the scenes !!

This should be simple but I am stuck somewhere in code or my understanding. Here my issue goes: I have a main document ‘MyBirthday’. I want to create the response documents ‘MyFamily Birthday’ linked to MyBirthday. I want this without submitting my Main document(I can save it).

What I did: I created Birthday xpage and 2 fields for Family birthday. On click of button ‘Create response doc 1’, first I save the main document using simple actions. Then I create response document via function in SSJS.

I created 2 similar buttons(1st for new doc, 2nd for existing doc): 1 just above which will save main document first then will call this function & the other button which will not save the main document but will call & create responses.

Function is as below:

function fncCreateResponseDoc(currDoc:NotesDocument)
{
    var name = sessionScope.get("FNAME")
    var Bday = sessionScope.get("FBIRTH")
    var respDoc:NotesDocument = database.createDocument()
    respDoc.replaceItemValue("Form","rfFamily") 
    respDoc.replaceItemValue("FName",name)
    respDoc.replaceItemValue("FBirthday",Bday)
    respDoc.makeResponse(currDoc)
    respDoc.save()
    respDoc = null
}

Then just below, I put a repeat to view these response documents. Data binding formula for repeat goes like this -> currentDocument.getDocument().getResponses()

Before saving the main document I set sessionScope variables:

sessionScope.put("FNAME",currentDocument.getItemValueString("FName"))
sessionScope.put("FBIRTH",currentDocument.getItemValueDateTime("FBirthday"))

Then in postSaveDocument event of this document1:

var currDoc:NotesDocument = currentDocument.getDocument(true)
fncCreateResponseDoc(currDoc)

Please help !!

1

1 Answers

1
votes

Ravi, most likely your currDoc doesn't have the docid since it hasn't been saved. Add a currDoc.save(); to your function in the beginning. also add respDoc.recyle(); before setting it to null. Furthermore burn a jostick for each ; you omitted (and don't try to argue about that <vbg>).

let us know how it goes.