xpages getDocument().getUniversalID() - xpages

I just want to test something about getting the UniversalID:
I create a computed field:
<xp:text escape="true" id="computedField3"
value="#{javascript:Cdoc.getDocument().getUniversalID()}">
</xp:text>
When I compose the doc. content which is on a Xpage, the computed field is already having some UNID and it is changing if I hit refresh. In lotus notes programming, the UNID could be get only if the current document was saved, having the default value #Text(#DocumentUniqueId).
Should I save first the Cdoc datasource to get the correct UNID? I know I'm missing something.
Thanks for your time

If you refresh your page in browser then actually a new document gets created. That's why you get a different UNID.
From your previous questions I know that you define your Cdoc as a data source with
<xp:this.data>
<xp:dominoDocument
var="Cdoc"
formName="fmPersContact">
</xp:dominoDocument>
</xp:this.data>
and that means that this Cdoc is created every time you open this XPage.
Update:
In addition, you get also a different UNID every time your field gets calculated on server when you do a partial refresh and document is not saved yet.

Related

Domino Document cannot be opened twice on public access xpage

I have an Xpage with access set to public for clients to fill in a form. When I send the client the link to the page and they open it for the first time. Everything runs smoothly. However, if they close the browser and click on the link again they receive this error:
{Unexpected runtime error
The runtime has encountered an unexpected error.
Error source
Page Name:/xpClientForm.xsp
Exception
Could not open the document
Invalid universal id}
I am using a switch facet to cycle between forms depending on the client type.
The domino document id is being stored in a sessionScope beforepageload and the document dynamically computes it based on that sessionScope variable.
Here is the code:
SessionScope assignment on beforepageload
var cData = getClientData(id);
sessionScope.docId = cData.docID;
Document datasource
<xp:panel style="height:100px" id="pnlDocData">
<xp:this.data>
<xp:dominoDocument var="document1"
formName="frmA" action="editDocument"
documentId="#{javascript:sessionScope.docID;}" scope="request">
</xp:this.data>
</xp:panel>
However when i execute this custom control on a page that does not have public access. It runs fine with no issues irrespective of how many times i open the link.
Any help will be greatly appreciated.
You need to set ignoreRequestParams="true" on the dominoDocument datasource. Otherwise it's using the document ID in the URL or trying to create a new document, which the user probably doesn't have access to do.
Computing the document ID is the less common scenario, which is using the URL for document location is the default.

Why DominoDocumentData.setConcurrencyMode has no effect for Domino document data source?

I used to save the current DominoDocument of the XPage in some way like:
UIViewRootEx2 view=(UIViewRootEx2) FacesContext.getCurrentInstance().getViewRoot();
DominoDocumentData ddd=(DominoDocumentData) view.getData().get(0);
DominoDocument dominoDoc=(DominoDocument) ddd.getDataObject();
//ddd.setConcurrencyMode("force");
dominoDoc.save();
To use the concurrencyMode property of the data source to avoid conflicts, I add the following line.
ddd.setConcurrencyMode("force");
I expect this behaves the same as setting the property in the XPage:
<xp:dominoDocument var="document1" formName="Test" computeWithForm="onsave" concurrencyMode="force"></xp:dominoDocument>
But it fails. It always uses the value set in the XPage source and ignores the value set in the code. Anybody knows the reason? Thanks.
I would say: works as designed. During one of the jsf phases the design is read and the value overwritten.
In JSF and thus XPages you don't mess from "Controller Code" (the stuff in your button) with the "View rendering" (your XPages source). You rather bind the property to your model (a scope variable is a good candidate) and let the runtime run its course.
So your code would be
<xp:dominoDocument var="document1"
formName="Test"
computeWithForm="onsave"
concurrencyMode="#{viewScope.myConcurrency}">
</xp:dominoDocument>
and
viewScope.myConcurrency = "force"
Hope that clarifies it.

xpages, get value of a field in a form from other form

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.
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}" />
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
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.

xpages display a new doc. inside a dialog

i have an issue that it gives me some headache lately.
In my XPage there is a view displaying some docs ( let say Pdoc as datasource ) and I open/create them inside a <xe:dialog>. This dialog has only Pdoc declared as datasource, and it inherits some values from the Xpage datasrouce. My clickable column formula is:
// some var declarations
var formName = rowData.getDocument().getItemValueString("Form");
if ( formName == "fmP" )
{ viewScope.put("dlgDocUnid", pe.getUniversalID())
getComponent("exampleDialog").show(); }
On the same XPage, I can create a new Pdoc using the same dialog via a button, New Pdoc.
The problem is: when I opened an existing Pdoc and then just save it or close it, and after I use the button to create a newNote => the old / previous ( already saved Pdoc ) is showed...
If firstly I just created a new note Pdoc, it works, and it is showing a new empty Pdoc.
My dialog data code:
<xp:this.data>
<xp:dominoDocument var="Pdoc" formName="fmPersContact"
ignoreRequestParams="true" scope="request" action="editDocument">
<xp:this.documentId><![CDATA[#{javascript:viewScope.get("dlgDocUnid");}]]></xp:this.documentId>
</xp:dominoDocument>
</xp:this.data>
I use the .documentId for the open method from the viewPanel. I think here is the problem. I think ,( I'm not sure), I should compute this documentId in such way that when I create a newNote this documentID shouldn't be anymore the viewScope.get("dlgDocUnid").
Thanks for your time.
If I understood correctly, you have defined two data sources within the XPage and you try to consume them in the dialog, right? Instead I suggest defining a single data source within a panel inside the xe:dialog.
I have blogged about a similar example. In this example, tooltip dialog has been used but it's the same logic, you might replace xe:tooltipDialog with xe:dialog.
http://lotusnotus.com/lotusnotus_en.nsf/dx/mini-patterns-for-xpages-parameter-editing-with-dialogs-1.htm
The idea here is that you use a viewScope variable named noteId. To open an existing document, set this variable to the note id of the existing document. To create a new document, the value will be set as NEW. Then you define the data source within the dialog according to this variable:
<xe:dialog>
<xp:panel style="width:500.0px">
<xp:this.data>
<xp:dominoDocument
var="document1"
formName="Parameter"
action="#{viewScope.noteId eq 'NEW'?'createDocument':'editDocument'}"
documentId="#{viewScope.noteId eq 'NEW'?'':viewScope.noteId}"
ignoreRequestParams="true">
</xp:dominoDocument>
</xp:this.data>
..... Dialog content ....
</xp:panel>
</xe:dialog>
When you put the data source inside the dialog, you don't refresh the page to load or prepare data sources before launching the dialog which is your current problem I guess.
Could it be that you forgot to deactivate the flag to ignore request parameters.
Sounds like the dialog is always associated with the current document instead of the parameters from the docid

xpages passing the UNID to other field

I have an input field:
<xp:inputText value="#{Cdoc.txt_UNID}" id="txt_UNID1"></xp:inputText>
The field txt_UNID is computed having the value: #Text(#DocumentUniqueID).
What I noticed is that even I just compose the xpage containing the document content the inputText already contains some UNID even if the xpage containing the doc content wasn't saved.
There is a button which is showing a dialog containing a field. I want this field to have the value of txt_UNID
Cdoc.save(); // I must save first the Cdoc datasource ?
getComponent('exampleDialog').show()
And the code for the field:
<xp:inputText value="#{Pdoc.txt_CompanieUNID}"
id="txt_CompanieUNID1" defaultValue="#{Cdoc.txt_UNID}">
</xp:inputText>
Thanks for your time.
If your question is whether or not you must first save the document in order to get the UNID, my answer is yes. In my tests, the UNID has changed from a new document to a freshly saved document. So, yes if the current document is new, save before getting the UNID. At least when it was a NotesXspDocument.
I also generally use JavaScript for this,
cdoc.getDocument().getUniversalId();
Otherwise, I am unsure what you are asking.
If PDoc is available at the same level of the hierarchy as CDoc, e.g. both are datasources assigned to the XPage / Custom Control or the same Panel, you could update PDoc on save, using PDoc.replaceItemValue("txt_CompanieUNID",Cdoc.getDocument().getUniversalID()). setValue should also work. Then you would not need the default value.
It just helps keep all business logic in one place. You could also check whether a value has already been set.

Resources