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

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.

Related

xpages: how to simulate form's auto launch properties

Is there a quick and easy way to convert forms that have auto launch first attachment and/or launch URL?
I know it can be coded in SSJS but I was just wandering if someone had a quick way of doing this.
Thanks
The following Domino URL command will open an attachment ...
http://Host/DatabaseName/View/DocumentName/$File/fileattachmentname
... where the DocumentName is effectively the lookup value shown in the first column which is sorted.
Add an xp:link control and code it open the attachment (in this example in a new window). For example, the following is an xp:link that could be added in an xp:viewColumn or xp:repeat or any iterator control. In this example the var for the iterator is set to "rowData" and the name for the link is returned from the ListName column and the url to launch the attachment is in the cLinkUrl column.
<xp:link escape="true" id="link1" target="_blank">
<xp:this.text><![CDATA[#{javascript:rowData.getColumnValue("ListName");}]]></xp:this.text>
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("cLinkUrl")}]]></xp:this.value>
</xp:link>
Since I wanted the code to be in the xpage, as it opens up either the document or the attachment depending on roles, I ended up adding this to the beforepageload event of the xpage (still need to add the role check to this though):
<xp:this.beforePageLoad>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var url = currentDocument.getDocument().getHttpURL();
var attachmentName = #AttachmentNames();
facesContext.getExternalContext().redirect(url.replace("?OpenDocument","/$File/"+attachmentName+"?OpenElement&target=_new"));}]]></xp:this.script>
</xp:executeScript>
</xp:this.beforePageLoad>

Xpages How to set default value to blank field after document has already been saved?

My PCModel document will go through several workflow processes, and the user will only add the necessary information at the appropriate stage. The user will select a dialogbox and be presented with a few fields.
For some of these fields I want to pre-populate a default value. However, my fields are bound to my Java object. and default code is ignored, I believe because there ALREADY is a value in the field, blank.
How can I add a default value, like the current user, to the bound field while still allowing the user to override this?
<xc:cc_CommonFormField id="cc_CommonFormField7" fieldName="buildUser" label="By Team Member">
<xp:this.facets>
<xp:comboBox id="comboBoxA" xp:key="field" value="#{PCModel.buildUser}"
defaultValue="#{userBean.commonName}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:"Select A Value|"}]]></xp:this.value>
</xp:selectItems>
<xp:selectItems
value="#{PCConfig.networkTeam}"/>
</xp:comboBox>
</xp:this.facets>
</xc:cc_CommonFormField>
My java object is normal.
Initialize the value in your Java bean
or
set the value somewhere in your SSJS code with
PCModel.buildUser = userBean.commonName

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.

How to edit the contents of a RichText field in Xpages using only a basic textarea

How do you disable the CkEditor for Rich Text fields so you only render a basic <texarea> tag with no editor whatsoever?
I'm sure I must be missing something obvious but I don't see to be able to create a document using an XPage with a field stored as RT without using the CkEditor. I want to be able to prompt the user to enter 'a lot' of text but only via a simple multiline input and have that stored as RT.
If I have a..
form with a RT field
an XPage with a xp:inputTextarea control bound to said field
a save button
a documentdatasource linked to that form
on save the document is created with the field value but it's stored as text rather than RT. Adding in computeWithForm to the dds properties doesn't help.
Is the only way to have some kind of querysave or custom converter to manually turn it into RT?
If I use the xp:inputRichText control it saves fine as RT but I don't want the CkEditor in the UI, just a basic . Is there a someway to do a editor=plain to the xp:inputRichText control?
I've been looking at trying to override the dojoType or renderType with no luck
Thanks!
You can use <xp:customConverter> in <xp:inputTextarea> to convert the text to rich text item.
For getAsObject you would write this code (document1 is your data source):
var rtitem:NotesRichTextItem = document1.getDocument().createRichTextItem("rtfield");
rtitem.appendText(value);
return null; // Return null as field has already been created
And for getAsString you would simply fetch the contents of rich text field and textual value.
value.getContentAsText()
The variable value is a standard variable which contains the actual value of the field. So you code for <xp:inputTextarea> would look something like this:
<xp:inputTextarea id="inputTextarea1" value="#{document1.rtfield}">
<xp:this.converter>
<xp:customConverter getAsString="#{javascript:value.getContentAsText()}">
<xp:this.getAsObject><![CDATA[#{javascript:var rtitem:NotesRichTextItem = document1.getDocument().createRichTextItem("rtfield");
rtitem.appendText(value);
return null;}]]></xp:this.getAsObject>
</xp:customConverter>
</xp:this.converter>
</xp:inputTextarea>
NOTE: If you wish to update the rich text field using the text area then you need to write additional code in getAsObject
I am not sure how to manipulate the field type. I assume that Domino know what is going on with the control in much the same way that the custom controls are formatted to match the content type. You might be able to force the content type.
I can present this as an alternative. You can do a custom toolbar in the ckeditor to remove the toolbar and make it appear like a normal text field. There may be UI complications with doing so though. You would also have a status bar to contend with to make it appear as a plain white box. There should be another dojo attribute type for this.
This code will give you a rich text box with no toolbar
<xp:inputRichText id="inputRichText1"
value="#{document1.content}">
<xp:this.dojoAttributes>
<xp:dojoAttribute name="toolbar">
<xp:this.value><![CDATA[#{javascript:var myToolbar = "[['']]";
return myToolbar}]]>
</xp:this.value>
</xp:dojoAttribute>
</xp:this.dojoAttributes>
</xp:inputRichText>

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