Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • Lotus Notes and Domino Application Development wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 6.0
  • 6.5
  • 8.0
  • 8.5
  • 8.5.1
  • 8.5.2
  • 8.5.3
  • action bar
  • Agents
  • Ajax
  • app dev
  • Application
  • beginner
  • C&S
  • calendaring and scheduling
  • client
  • composite applications
  • Controls
  • converters
  • css
  • Custom controls
  • Data Binding
  • db2
  • design elements
  • dialog boxes
  • Documents
  • Dojo
  • Domino
  • Domino Designer
  • Domino Designer 8.5
  • DXL
  • Eclipse
  • error handling
  • errors
  • extensions
  • FAQ
  • Forms
  • formulas
  • getting started
  • globalization
  • Help
  • html
  • Installation
  • interface
  • internationalization
  • iPhone
  • Java
  • JavaScript
  • localization
  • Lotus Domino Designer
  • LotusScript
  • LotusSphere
  • LotusTechInfo
  • menu bar
  • Mobile
  • new user
  • Notes
  • Notes 8
  • notes.ini
  • NSD
  • OpenNTF
  • partial update
  • performance
  • Pickers
  • Portal
  • presentations
  • programming
  • Redbooks
  • Requested Articles
  • roadmap
  • rooms and resources
  • samples
  • Scripting
  • security
  • tabs
  • templates
  • themes
  • Tips
  • toolbar
  • troubleshooting
  • tutorials
  • validation
  • variables
  • video
  • VideoFest
  • View
  • view control
  • ViewPanel
  • Views
  • web
  • Web apps
  • Web services
  • webdev
  • XML
  • Xpage
  • XPages
  • XPages Extensibility API
  • xsp-config
  • データソース
  • 九州地区ノーツパートナー会
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > Developing XPage Applications > NotesXSPDocument sample JavaScript code for XPages
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

NotesXSPDocument sample JavaScript code for XPages 

expanded Abstract
collapsed Abstract
Here is sample JavaScript code for the class NotesXspDocument. Eventually this sample code will find its way into the documentation. Corrections and comments are appreciated.
ShowTable of Contents
HideTable of Contents
    • 0.1 NotesXspDocument
    • 0.2 getAttachmentList
    • 0.3 getDocument
    • 0.4 getForm
    • 0.5 getItemValue
    • 0.6 getItemValueArray
    • 0.7 getItemValueDate
    • 0.8 getItemValueDateTime
    • 0.9 getItemValueDouble
    • 0.10 getItemValueInteger
    • 0.11 getItemValueString
    • 0.12 getNoteID
    • 0.13 getParentDatabase
    • 0.14 getParentId
    • 0.15 getValue
    • 0.16 hasItem
    • 0.17 isEditable
    • 0.18 isNewNote
    • 0.19 isResponse
    • 0.20 removeAllAttachments
    • 0.21 removeAttachment
    • 0.22 removeItem
    • 0.23 replaceItemValue
    • 0.24 save
    • 0.25 setValue

NotesXspDocument


This Open simple action uses scripts to set a condition and to specify a target.

<xp:button id="button1" value="Open parent"><xp:eventHandler event="onclick" submit="true" refreshMode="complete">	<xp:this.action>
	<xp:actionGroup
			condition="#{javascript:document1.isResponse()}">
			<xp:openPage name="/main.xsp"
				target="#{javascript:return document1.getParentId()}">
			</xp:openPage>
	</xp:actionGroup>
</xp:this.action></xp:eventHandler></xp:button>


getAttachmentList


This onclick event gets the names of any attachments to the document. The variable requestScope.xml is bound to a multiline edit box.

var alist = document1.getAttachmentList("body");
if (alist.isEmpty()) {
		 requestScope.alist = "No attachments"
} else {
		 var result = alist.length.toString() + " attachments\n";
		 var alisti = alist.iterator();
		 //		 Each element is of type NotesEmbeddedObject
		 while (alisti.hasNext()) {
		 		 result = result + alisti.next().getName() + "\n";
		 }
		 requestScope.alist = result;
}


getDocument


This button onclick event gets the XML for the document (updated with any changes made in the data store) associated with the current XPage. Elsewhere on the XPage requestScope.xml is bound to a multiline edit box.

requestScope.xml = document1.getDocument(true).generateXML()


getForm


This code computes the form for a data source, specifying it as the same form used for document1.

return document1.getForm()


getItemValue


This data binding for a multiline edit box returns the values of the Numbers item in the document associated with the current XPage.

var v = document1.getItemValue("Numbers");
if (v.isEmpty()) {
		 return "Numbers is empty or doesn't exist";
} else {
		 var result = "";
		 var vi = v.iterator();
		 while (vi.hasNext()) {
		 		 result = result + vi.next().toFixed() + "\n";
		 }
		 return result;
}


getItemValueArray


This data binding for a multiline edit box returns the values of the Numbers item in the document associated with the current XPage.

var array = document1.getItemValueArray("Numbers");
if (array.length == 0) {
		 return "Numbers is empty or doesn't exist";
} else {
		 var result = "";
		 for (var i=0; i<array.length; i++) {
		 		 result = result + array[i].toFixed() + "\n";
		 }
		 return result;
}


getItemValueDate


This computed field that returns the value of the datetime item in the document associated with the current XPage.

var d = document1.getItemValueDate("datetime");
if(d == null) {
		 return "datetime is empty or doesn't exist."
} else {
		 return d.toLocaleString();
}


getItemValueDateTime


This data binding for a computed field returns the value of the datetime item in the document associated with the current XPage.

var d = document1.getItemValueDateTime("datetime");
if(d == null) {
		 return "datetime is empty or doesn't exist."
} else {
		 return d.getLocalTime()
}


getItemValueDouble


This value for a computed field returns the value of the Number item in the document associated with the current XPage.

var n = document1.getItemValueDouble("Number");
if(n == 0.0) {
		 return "Number is empty or doesn't exist."
} else {
		 return n;
}


getItemValueInteger


This value for a computed field returns the value of the Number item in the document associated with the current XPage.

var n = document1.getItemValueInteger("Number");
if(n == 0) {
		 return "Number is empty or doesn't exist."
} else {
		 return n.toFixed();
}


getItemValueString


This data binding for a computed field returns the value of the Subject item in the document associated with the current XPage.

var s = document1.getItemValueString("Subject");
if(s == "") {
		 return "Subject is empty or doesn't exist."
} else {
		 return s;
}


getNoteID


This button assigns the note ID of the document associated with the current context to a session variable.

sessionScope.noteid = document1.getNoteID()


A button on another page uses the session variable to determine the target document for an Open simple action.
return sessionScope.noteid


The button for the Open simple action is visible only if the note ID is set.
sessionScope.noteid != null


getParentDatabase


This computed field displays the title of the parent database of the document associated with the current context.

return document1.getParentDatabase().getTitle()


getParentId


This code gets the target document for an Open simple action.

return document1.getParentId()


This is the condition for a group that precedes the above event.

document1.isResponse()


getValue


This button onclick event totals the numbers in a multiline edit box.

var v:java.util.Vector = document1.getValue("numbers");
var vi = v.iterator();
var total = 0.0;
while (vi.hasNext()) {
		 total = total + vi.next() * 1.0; // need * 1.0 to force vi.next() to number
}
document1.setValue("numbers", total)


hasItem


This computed field returns the value of an item in the document associated with the current XPage if the item exists.

if(document1.hasItem("number")) {
		 return document1.getItemValueDouble("number").toString();
} else {
		 return "number does not exist"
}


isEditable


This button onclick event saves the document if it is in edit mode.

if (document1.isEditable()) {
		 document1.save();
		 requestScope.status = "Document saved";
} else {
		 requestScope.status = "Document not in edit mode";
}


isNewNote


This label displays a message if the document associated with the current XPage is new and an item value if it is not new.

if(document1.isNewNote()) {
		 return "New subject";
} else {
		 return document1.getItemValueString("subject");
}


isResponse


This code gets the target document for an Open simple action. The target document is its parent.

return document1.getParentId()


This is the condition for the group to which the above event belongs.

document1.isResponse()


removeAllAttachments


This button onclick event removes all attachments from the body item if there are any.

if (document1.getAttachmentList("body").isEmpty()) {
		 requestScope.alist = "No attachments in body";
} else {
		 document1.removeAllAttachments("body");
		 requestScope.alist = "All attachments removed from body";
}


removeAttachment


This button onclick event removes an attachment from the body item if it exists.

if (document1.getAttachmentList("body").isEmpty()) {
		 requestScope.alist = "No attachments in body";
} else {
		 if (document1.removeAttachment("body", requestScope.rname)) {
		 		 document1.save();
		 		 requestScope.alist = "Attachment " + requestScope.rname + " removed from body";
		 } else {
		 		 requestScope.alist = "Attachment " + requestScope.rname + " does not exist";
		 }
}


removeItem


This button removes the number item from the current document if it exists.

if (document1.hasItem("number")) {
		 document1.removeItem("number");
		 document1.save();
		 requestScope.alist = "Removed number item";
} else {
		 requestScope.alist = "No number item in document";
}


replaceItemValue


This button increments the value of an edit box by 1 and saves the new value.

document1.replaceItemValue("counter", document1.getItemValueInteger("counter") + 1;
document1.save();


This button sets values for a multi-value edit box without saving them.

var n = new Array(22, 33, 44);
document1.replaceItemValue("number", n);


This button sets values for a multi-value edit box without saving them.

var n = new java.util.Vector();
n.addElement(22);
n.addElement(33);
n.addElement(44);
document1.replaceItemValue("number", n);


save


This button sets a value for the subject item if it has none, saves the document, and opens the previous page.

if (document1.getItemValueString("subject").trim().length == 0 {
		 document1.setValue("subject", "No subject");
}
document1.save();
context.redirectToPrevious();


setValue


This button increments the value of an edit box by 1 and saves the new value.

document1.setValue("counter", document1.getItemValueInteger("counter") + 1;
document1.save();


This button sets values for a multi-value edit box without saving them.
var n = new Array(22, 33, 44);
document1.setValue("number", n);


This button sets values for a multi-value edit box without saving them.

var n = new java.util.Vector();
n.addElement(22);
n.addElement(33);
n.addElement(44);
document1.setValue("number", n);

expanded Article information
collapsed Article information
Category:
Developing XPage Applications, Developing XPage Applications for Notes Client, JavaScript,
Tags:

This Version: Version 1 September 21, 2010 9:38:40 AM by Robert Perron  IBMer

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (1)
collapsed Versions (1)
Version Comparison     
Version Date Changed by               Summary of changes
This version (1) Sep 21, 2010 9:38:40 AM Robert Perron  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use