03 Troubleshooting
Designer
Retrieving datetime values and dateranges using getItemValue
The getItemValue method in the LotusScript NotesDocument and Java Document classes returns the beginning and end date-times of a range as individual date-time values.
For example, if you have the range 1:00-10:00 in a DateTime field, Document.getItemValue will return 1:00;10:00 as separate date-time values, not as a range. In Java, use the getFirstItem method to get the DateTime item you want to manipulate, then use the getText property to get a plain text representation of the contents of the item. This will allow you to parse the contents of the field for individual date-time values and date-ranges. For LotusScript, use the GetFirstItem method and the Text property to achieve the same results.
Examples:
1. This Java example parses the contents of a DateTime field that has been retrieved using the getFirstItem and getText methods. Individual date-time values and date-ranges are identified by their separators. Hyphens (-) separate the beginning and end date-time values of a date-range and semicolons (;) separate individual date-time values from each other, or from date-ranges. In this example, date-time values are returned first, then date-ranges.
import java.util.Vector;
import java.util.Enumeration;
public class DTParser {
private int posHyphen;
private int posSemicolon;
DTParser(int iHyphen, int iSemicolon)
{
setPosHyphen(iHyphen);
setPosSemicolon(iSemicolon);
}
private void setPosHyphen(int iHyphen)
{
posHyphen = iHyphen;
}
private void setPosSemicolon(int iSemicolon)
{
posSemicolon = iSemicolon;
}
public void resetPos(int iHyphen, int iSemicolon)
{
setPosHyphen(iHyphen);
setPosSemicolon(iSemicolon);
}
public boolean isDateTimeRange(String sDateTime)
{
posHyphen = sDateTime.indexOf("-", posHyphen);
posSemicolon = sDateTime.indexOf(";",
posSemicolon);
// Encountered an individual DateTime entry
if ((posSemicolon < posHyphen) &&
!(posSemicolon == -1))
{
posHyphen = 0;
posSemicolon++;
return false;
}
// Encountered a DateTime range
if ((posHyphen < posSemicolon) &&
!(posHyphen == -1))
{
posHyphen++;
posSemicolon++;
return true;
}
}
// Encountered a DateTime range - last in
// the list
if (!(posHyphen == -1) && (posSemicolon ==
-1))
{
return true;
}
// Encountered an individual DateTime entry
// - either no DateTime ranges follow this
// entry or this entry is the last in the
// list of DateTimes
if (posHyphen == -1)
{
return false;
}
return false;
}
public String assembleDTString(Vector vSchedule)
{
String sSchedule = new String("");
Object objDT;
Enumeration enumItems;
for (enumItems = vSchedule.elements();
enumItems.hasMoreElements();)
{
objDT = enumItems.nextElement();
sSchedule =
sSchedule.concat(objDT.toString()+",");
System.out.println("sSchedule="+sSchedule);
}
return
(sSchedule.substring(0,sSchedule.length()-1));
}
}
2. This LotusScript example uses the GetFirstItem method to retrieve the data from a DateTime field and then uses the Text property to get the contents of the field in plain text. The ReplaceItemValue method is used to put the data in a field called "ReturnValue". The dashes in the date-ranges are preserved in the output.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection
Dim item As NotesItem
Set db = session.CurrentDatabase
Set collection = db.AllDocuments
Set doc = collection.GetLastDocument()
Set item = doc.GetFirstItem("DT")
Call doc.ReplaceItemValue("ReturnValue",item)
Call doc.Save(True,False)