I have an xpage that I am trying to accomplish the following.
-
User inputs “course_input” into the field.
-
Clicks button “add”
-
The button then appends the course_input to the multi-value field “eligable_courses”
-
The process can be repeated as needed.
I have the following code on the “add” button now, but I am getting some wierd results but not sure why.
code:
var courses = sessionScope.course_input
if (document1.getItemValue(“eligable_courses”) ==null){
var updated = courses}
else{ var updated = courses+document1.getItemValue("eligable_courses")}
document1.replaceItemValue(“eligable_courses”,updated)
sessionScope.course_input=null
Example output:
Course 3[Course 2[Course 1]]
Subject: appendtotextlist
It’s very similar to lotusscript (but then I’m assuming you wouldn’t know how to do this in ls either)
var courses = sessionScope.course_input
if (document1.getItemValue(“eligable_courses”) ==null){
document1.replaceItemValue(“eligable_courses”,courses)}
else{
var item:NotesItem = document1.getFirstItem(“eligable_courses”);
call item.appendToTextList(courses)
)}
Subject: error
I am getting an error using your code:
Script interpreter error, line=13, col=32: Error calling method ‘getFirstItem(string)’ on an object of type ‘NotesXspDocument [Static Java Wrapper, com.ibm.xsp.model.domino.wrapped.DominoDocument]’
Subject: code
Can you post your whole code, how did you instantiate document1? It should be a NotesDocument
Subject: code
document1 is the datasource set at the xpage level. It is a notes form.
The code posted previously is on a button control. That is the entire code.
Subject: code
OK, then you need to use
var item:NotesItem = document1.getDocument().getFirstItem(“field”)
Subject: item is null
Using the following code:
var courses = sessionScope.course_input
if (getComponent(“inputTextarea1”).getValue() == null){
document1.replaceItemValue(“eligable_courses”,courses)}
else{
var item:NotesItem = document1.getDocument().getFirstItem(“eligable_courses”)
item.appendToTextList(courses)
}
sessionScope.course_input=null
I am still getting an error saying that item is null. This only happens after the first time through.
I really appreciate the help btw…
Subject: You can’t “append” to something that doesn’t exist yet.
So on the first time, you call getFirstItem when there is no item yet, and it returns null. You must test whether item is null, and use replaceItemValue method instead.