I have two forms Job and Comment,type of these forms are document and response. There is a field in the Job form that save name of developer and there is a field in the Comment form that I want to get the name of developer from Job when I want to create a comment for selected job.
3 Answers
One way to get field values from a parent document (in your case from the Job document) is to use a data context to create a parentDoc object. You can then refer to this parentDoc object to get field values from the parent document.
Start by creating a parentDoc data context:
<xp:this.dataContexts>
<xp:dataContext var="parentDoc">
<xp:this.value><![CDATA[#{javascript:
return database.getDocumentByUNID(currentDocument.getParentId());
}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
If you just want to display a value from the parent document (and not save it in the response document), you can then use a computed field to display the value from the parent document (using expression language to refer to the field from the parentDoc object):
<xp:text escape="true" id="displayParentField" value="#{parentDoc.field}" />
You can also use the value from the parent document as the default value for an input field:
<xp:inputText id="responseValue" value="#{currentDocument.responseField}" defaultValue="#{parentDoc.field}" />

- 21,331
- 3
- 29
- 76
-
Hi Lausten, Thank you for your answer. I tested your answer but I don't know why it doesn't work for me? then I used this code in default value of Assign field in Comment form(Response form). var parentDoc= database.getDocumentByID(document1.getParentId()) return parentDoc.getItemValueString("developer1") It gets ID of parent document but doesn't set value of developer field from Job form(parent form) in Assign field of Comment form.What is wrong? – Maryam Oct 16 '14 at 22:39
-
Is parentDoc getting assigned to a backed document? – Per Henrik Lausten Oct 17 '14 at 05:34
-
1Thank you so much Lausten I made a mistake in parentDoc.getItemValueString("Developer") – Maryam Oct 19 '14 at 21:09
Short answer, you filter the 2nd data source with the value of the field. It could be the response field on the response doc or the value of the field that exists on both docs.
Long answer, This is a common xPages question, one I have asked myself. Take a look at this question. xPage with multiple datasources has the second datasource always opened in edit mode

- 1
- 1

- 1,362
- 7
- 22
A simple solution, I added the below code in default value of Assign field in response form it works now
var parentDoc = database.getDocumentByID(document1.getParentId())
return parentDoc.getItemValueString("Developer")
Thank you Per Henrik Lausten your answer helped me to solve this issue.

- 71
- 8