Skip to main content link. Accesskey S

XPages Wiki

Submit Search

YouAtNotes XPages Wiki


Home > Server JavaScript > Work with documents and fields on the XPage

Work with documents and fields on the XPage

ShowTable of Contents

Get and set a field on the XPage

Server JS

getComponent("elementName").getValue();
getComponent("elementName").setValue("something");


Note: you cannot access or set fields with visible=false. If you want to work with a field, but don't want to display it, give the field a CSS class with "display:none".

Get submitted value before validation


getComponent("elementName").getSubmittedValue()

Client JS


document.getElementById("#{id:elementID}").value;


Get a computed field's value:

document.getElementById("#{id:elementID}").innerHTML;


(thanks, Jerry Shelly!).

Access backend Notes document


Fields on the XPage are bound to a datasource. If the datasource represents a Notes document, you can access that with:

var doc:NotesDocument = datasourcename.getDocument();


Note: the variable "doc" is typed with "NotesDocument" here so that the IDE can give us a help for properties and methods.

Note: use datasourcename.getDocument(true) to get a backend document which has the changes which were applied to the UI document (kind of NotesUIDocument.refresh).

To work with a field, you can use

var doc:NotesDocument = datasourcename.getDocument();
doc.replaceItemValue("somefield", "somevalue");


Or to get a field which is in the backend doc but not on the XPage:

var v = datasourcename.getValue("fieldname");

Work with a document in the click event of a submit button


You can access the document and set fields as described above in the onClick event of a submit button.
But you have to redirect to another XPage after that by yourself using context.redirect() then.

Run a agent on document save


Something like the "WebQuerySave" agent in classic domino development. In datasource -> querySave event run

var agent:NotesAgent=database.getAgent("agentname");
agent.run(datasourcename.getDocument().getNoteID());
Im Agent bekommt man das Dokument dann via notesDatabase.GetDocumentByID( NotesAgent.ParameterDocID )


In the agent you get the noteID of the saved document with

set session = new notesSession
set database = session.currentDatabase
set agent = session.currentAgent
set doc = database.getDocumentByID(agent.parameterDocID);

Check for edit mode and set edit mode


<datasource>.isEditable()


returns true if is in editmode.

There is no "setEditMode()" method in the NotesXSPDocument, but Tibor Koch found a solution for setting edit/read mode without using a redirect:

function setEditMode(doc:NotesXSPDocument, editmode:boolean) {
	try {
		var cl:java.lang.Class = java.lang.Class.forName("com.ibm.xsp.model.domino.wrapped.DominoDocument");
		var method:java.lang.Method;
		var paramTypes = new Array();
		paramTypes[0] = java.lang.Boolean.TYPE;
		method = cl.getMethod("setEditable", paramTypes);
		var params = new Array();
		params[0] = new java.lang.Boolean(editmode);
		method.invoke(doc, params);	
} catch (e) {
	print("setEditMode error: "+e);
}
}


As an alternative, you can use the tip from John Mackey from our blog:

var url=view.getPageName()+"?action=editDocument&documentId="+document.getNoteID();
context.redirectToPage(url, false);


Check if a field is disabled


getComponent("<fieldname>").disabled


returns true if the field is disabled.

Set fields in backend document in QuerySave event


XPage -> events -> Datasource-Name -> querySave: use

Datasource.replaceItemValue("fieldname", "value");


instead of

Datasource.getDocument().replaceItemValue("fieldname", "value");

Use dynamic value binding for a field


( Discovered by Tommy Valand )
You can change / set the value binding for a field at runtime:

var application = facesContext.getApplication();
var scopeKey = "exampleKey"
var valueBinding = application.createValueBinding( '#{viewScope.' + scopeKey + '}')
getComponent( 'id-of-a-field' ).setValueBinding( 'value', valueBinding );


(In this example a viewScope field is used for value binding.)

Define dynamic value binding for a field at development time in the XML source


In the XML source of your XPage, you can write something like this:

<xp:inputRichText id="rtBody" 
value="#{dominoDoc[42]}"/>


which would bind the RichText field to the 42nd field of the document datasource "dominoDoc". While using an index number here is of limited usage, you can also use a fieldname in the brackets:

<xp:inputRichText id="rtBody" 
value="#{dominoDoc['myfield']}"/>


And finally you can use EML syntax to dynamically compute a fieldname, for example using an applicationScope variable:

<xp:inputRichText id="rtBody" 
value="#{dominoDoc[applicationScope.bodyFieldName]}"/>
See what's possible with Xpages.
Have a look at our ServiceCommunicator website
and the YouAtNotes Support.
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this wiki help you?
Did this saved you time? Express your gratitude by making a donation:
PayPal - The safer, easier way to pay online!