xpages passing the UNID to other field - xpages

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.

Related

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 should I use ignorerequestParams set to true

based on these questions:
xpages UNID of documents / why it is changing
xpages why my field value isn't copied correctly
i noticed, unfortunately, some computed field which stores the UNID is changing if I hit refresh / F5.
my XPage has defined one datasource ( Cdoc ) and it contains a button which shows a dialog. this dialog has defined other datasource ( Pdoc ). The dialog contains several fields, which inherit some values from Cdoc...
Should I use ignorerequestParams property for one of these datasources? Can you explain the meaning of this property?
What happens:
The field which stores the UNID of the Cdoc after I show the dialog and create some Pdoc and list it in a viewPanel inside the XPage ( Cdoc datasource ) and then hit F5 the Cdoc UNID is changing ... even if it is computed.
Also, if the doc. isNewNote() the url is something like this:
server/Test.nsf/doc.xsp?action=newDocument
even after I call Cdoc.save(). I think this could be a reason why the computedField which stores the UNID is changing when I hit refresh => a newDoc is created.
Meanwhile, I put the ignoreRequestParams set to true just for the dialog ( Pdoc ).
Thanks for your time!
By default, the UNID and action (open, create, edit) are defined by the URL query string, i.e. the request parameters. With requestParamPrefix you can define which entry in the query string is used to find the document parameters for this datasource. By default that's documentId. But if you want to manage the UNID and action yourself through code, that's when you need to set ignoreRequestParams="true".
If you have two datasources on a page, you will need to use either ignoreRequestParams or requestParamPrefix on one of them. If not, you're editing the same document in both datasources.

xpages embedded view or view panel

I know it is a very simple question , but I'm trying to see the difference between a view panel ( that I drag from the Container Controls ) and an embedded view.
How can I add an embedded view on my xpages?
Or the 2 items are one and the same.
The reason why I'm asking this question: I have a view panel on my xpage ( I thought it is like an embedded view in clasic lotus notes programming ) where I have listing some docs. The first column is categorized based on the UNID document.
I noticed if I compose again another document, this view contains all the previous docs., and all the UNID categorized. The view panel isn't empty.
In lotus notes programming:
If I have a main form and a computed text field with #Text(#DocumentUniqueId) and some button for composing another form ( of course, when clicking the button I saved the main form to obtain the UNID ), and this form has the same text field name as the previous - I'm passing the UNID to this second form. If the main form contains an embedded view listing all documents saved from the second form I will use the first column categorized and hidden with the name of the field from the second form ( which will contain the UNID ). If I save and close the 1st main, and then I'll compose another main form, the embedded view is not listing the previous documents already saved.
Well, this view is already created.
I did drag and drop this view in myxpage. I have a button inside myxpage that shows a dialog. Here a datasource is declared, the dialog containing some fields. In the main xpage ( where is defined another datasource ) there is a computed field which takes the UNID of the document. Before I click the dialog I save the first datasource, to pass the value UNID to other field inside the dialog.
I save the datasource from the dialog & close the dialog, and then the view panel ( which is the view from the lotus notes classic presented above ) lists the doc. If I close the main xpage ( save it if is a new one ) and then open another main document, the view isn't empty, it contains the previous document lists. ( I tried also to hide it, if the xspDoc is new. But when I try adding other docs. from the dialog, the view panel lists also the previous documents from the previous doc., even if the UNIDs are distinct )
Thanks in advance.
To explain this best, it's good to consider what a view and an embedded view in Notes Client is. A view determines the look and feel, like a View Panel and by default will show all documents found by the selection criteria. So in this case the documents available correspond to a dominoView datasource bound to the underlying view with no additional criteria defined.
An embedded view still uses the view to determine the look and feel, but will not display the first column (that's effectively a property of the embedded view "control" in Notes Client). In the View Panel you choose which columns display, so you would need to code that yourself on the View Panel, where you choose which columns to display. The embedded view also has a property to define the single category. But the View Panel and other repeating containers (like Data Table and repeat control) don't restrict the data available, that's done by the datasource - a dominoView or e.g. a ViewEntryCollection for anything other than the View Panel. So in that you set the filter.
However, a new document does not have a UNID, so it cannot restrict what is displayed. Instead, I think a good approach is to set the visibility so the View Panel is only displayed if it's not a new document. You can use loaded, if you fully reload the page after save, or else rendered.
First off, this is not a stupid question.
I am assuming you are using a self implemented parent response system and have a view sorted by the parent UNID. Under the data source of the view panel, find the the "filter by category name" option. there compute the UNID value, or category value you are searching for.
Steps:
insure that the background view is categorized (ascending order is best to insure that this works, though I doubt it is needed)
drag (my favourite is the dynamicViewPanel) a view control onto the xpage.
Under Properties/Data there is a place to calculate the value of the category to show. If you want an exact match, check the exact match check box.
If you mistype the category value or the value is not there, then no documents will be shown.
if you put in an empty value all documents are shown (at least in the tests that I can remember)
if documents are returned, the categorized column is automatically hidden.
EDIT
If you are reading the value from a field, you can use the code:
xspDoc.getItemValueString("fld");
If you are searching based on the UNID, again, hide the viewPanel if the document is new. If the value is not yet set, also hide the panel.
If you have two custom controls, even if a custom control is embedded in the second, you cannot easily have one custom control access the values of the datasource in another. I am sure there are ways to trick this into working, but in this case, use a viewScope variable to access the values and possibly an onLoad, onChange or onSave event to update the viewScope variable. Make sure to verify that the result is not null or empty by either printing it out to the server log or another field.
Final Edit after question edit/expansion
These are the steps that I would take to do what you described.
You have your parent document XPage. Insert all fields for this Xpage.
Drag a dynamicViewPanel onto the XPage. If parentDoc is New, then hide.(this could be a custom control in theory, but if you are having trouble, try it without for the sake of trouble shooting.
Set dynamicViewPanel datasource to ignoreReqeustParams.
Calculate the datasource and setting the "Filter by category name" filter. When computing this, for the sake of ease and troubleshooting, print this value out to the server, or other logging mechanism. You can delete it later.
Verify that the correct UNID/Value is being inserted into the document you create in the dialog.
If you are using a scoped variable to hold the filter value, be sure you are using viewScope and not appliationScope or sessionScope.
if you are using a custom control and standard parameters (not scopedVars), verify that the compositeData variable is being updated with a log or server print.
Consider setting Dialog Properties/AllProperties/basics/refreshOnShow to true
Play with the partial refresh option for the dialogOpen action, test a full vs partial refresh.
Remember to set the ignoreRequestParams for the document you are creating in the dialog to true
Consider making the new document data source created in the Dialog to request scope.
And of course consider and test all datasources being defined on the XPage on not some here, some there.
Verify that you are taking the value of the UNID from the main document and not the new dialog document by mistake!
Those are all of the tips I can think of right now, pretty much in the order I'd try them in. If that does not help, then I suspect there is a piece of this puzzle that you are not including in the question. Remember, try to keep things as simple as you can. You can over think things, make things harder than they need be.

Multiple data sources in XPages

I have 2 xpages that interact together. The first acts as a homepage and allows the user to create a new document and fill out some basic header information. The button to create the new document, sets a sessionScope var with the NoteID. It then saves document1 and opens the same document using another xpage.
The second xpages is bound to document1, and uses the sessionScope to edit the document. This xpages contains and editPanel bound to document2. I want to create a child document to document2. This works but what happens is document1 is also saved as conflict. It is also saved as a second main document.
I DO NOT want to save document1 at all, but can't seem to prevent it. The button that creates document2 uses the simple action save document, and specfies document2.
HELP, I have tried everything, and have been stuck on this for 2 days.
Thanks!
Steve
To bind to multiple datasources, on your XPage, under Properties expand Data and set "Ignore Request Params" to TRUE
If you change the type of your buttons, to a simple button instead of a submit button, and handle the doc.save() yourself should solve your problem.
The Save Document simple action accepts the name of the data source to save as a String argument. If supplied, it will only save that specific data source.

xPages - adding a field down the track

I want to add a field to an existing xPage, and need to run past a few xPage fundamentals to check their validity.
I have done the following:
In order to ensure that my dev and prod sites work, the form the document is bound to is calculated (as the datasource resides in a diff db).
My new field is called 'NewField', and I have used simple data binding, chosen document1 (same as the rest of the fields on my document), and entered the new field name (can't select from the drop down as the document is calculated).
I have also created the field on the actual notes document, however I did not think I HAD to do this? Also, it's on a calculated subform so not sure if this is relevant? This is an xpage version of an existing notes form - both client and web access are applicable for the application.
I thought it would create the field specified in 'Bind To' if it was missing, however even with it on the notes form, it still does not store the value.
Whats gone wrong:
The field is created on the document, however the value is not being populated. The value stored against the notes document is an empty string.
There is nothing complicated here, not doing anything funky, yet the value is not mapped?
The rest of the fields (created when I created the initial document) are mapped correctly.
Any suggestions? Is this a rookie error with adding fields to an existing xPage?
A
As requested, here is the code for both the data binding and a field that does work, and one that does not.
Here is my initial code to define document1. It does call an agent post save, however this agent does nothing with the field value that is not being assigned.
<xp:this.data>
<xp:dominoDocument var="document1" action="openDocument">
<xp:this.databaseName><![CDATA[#{javascript:var sname = ("","test\\testdb.nsf");
return sname;}]]>
</xp:this.databaseName>
<xp:this.formName><![CDATA[#{javascript:return "MainForm"}]]>
</xp:this.formName>
<xp:this.postSaveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var sname = #Name([CN]",#Subset(#DbName(),1));
var dbname = "test/testdb.nsf";
var dbTest:NotesDatabase = session.getDatabase(sname, dbname);
if (dbTest.isOpen()){
ag = dbTest.getAgent("UpdateDoc");
noteid = document1.getDocument().getNoteID();
ag.run(noteid);
} }]]></xp:this.script>
</xp:executeScript>
</xp:this.postSaveDocument></xp:dominoDocument>
</xp:this.data>
And then here is the code for the field assignment that is not working.
<xp:inputText value="#{document1.NewField}"
id="inputText25" disableClientSideValidation="true" styleClass="entryboxes">
</xp:inputText>
And then here is the code for a field assignment that is working.
<xp:inputText value="#{document1.CLRef}"
id="inputText4" rendered="#{javascript:#IsNewDoc()}" styleClass="entryboxes">
</xp:inputText>
I thought that this was fairly standard.
update 8/10
So - I have worked out that this happens only when I have conditionally hidden cell. This has a basic formula, asking the row to be visible based on the value of another field. The display / no display functionality is working (see below for code), yet, for a reason unknown to me, it does not save the value.
var hw = getComponent("module");
var hwv = hw2.getSubmittedValue();
hwv == "Product1" || hwv == "Product2" || hw2v == "Product3"
If I create any other field NOT hidden (and make up the field name), it maps to the document correctly (as I thought it should). The good news is I have managed to replicate with a new form, so it appears to be with me wanting to hide a row conditionally, and not an issue with my form? Any ideas?
OK - I continued to have issues with the field mapping when the cell was hidden in certain conditions. So, I ended up making the cell visible, and then having the field mandatory only in certain circumstances. So, question not answers, but a work around used.

Resources