1
votes

The only way i have found to store date in a Datetime field in a notes form is this:

theDoc2.replaceItemValue("lastAccess",session.createDateTime("Today"));

But this only creates a Date, not DateTime. Also, i dont want to create a static time like "Today 12" but i want the current datetime dynamicly.

Using this i get an error (Exception occurred calling method NotesDocument.replaceItemValue(string, Date) null):

theDoc2.replaceItemValue("lastAccess",@Now());

and using this, the form field changes from Date/Time to Text data type and i want to keep Date/Time type:

theDoc2.replaceItemValue("lastAccess",@Now().toLocaleString);

Any ideas?

3
When I use doc.replaceItemValue("dateField",session.createDateTime("Today")); I get a date field stored with both date and time. Have you checked the document properties to verify that your field does contain both date and time?Per Henrik Lausten
It is Date/Time List in document properties. The field is set to display both date and time but still with "Today" it only saves the date.mike_x_

3 Answers

6
votes

Just gave it a try:

as you wrote, .replaceItemValue("fieldName", @Now()) throws an error.

However, I got it to work with

.replaceItemValue("fieldName", session.createDateTime(@Now()))

In that case the value is stored in the Notes field as Time/Date with all necessary components as in

17.01.2014 12:45:51 CET

From what I can see, difference between the two is that @Now() returns a Date data type, whereas session.createDateTime() returns a NotesDateTime object

On the other hand, for me it's also working with your original method:

session.createDateTime("Today")

Don't know what's causing the prob on your side; do you have an editable represantion of the field on you xpage? If so, does it have some kind of converter enabled which could do some filtering during submit?

1
votes

i will answer my own question as i found a way. Please comment if you think it is not correct or best practice...

theDoc2.replaceItemValue("lastAccess",session.createDateTime("Today"+@Now().toLocaleTimeString()));
0
votes

A little late, but I had the same problem, but this method resolved it:

        DateTime datumtijd = session.createDateTime("Today");

        datumtijd.setNow(); //!!!!!!

        System.out.println((datumtijd).toString());

Hope it helps :)