سؤال

I want to display the time when a document is created via xpages. In clasic lotus notes I'd use computed when composed field.

A computed field is displaying the current date:

session.createDateTime("Today") 

How can I display the current time ( when I compose a document / an xpage ) ?

I tried something like this in a computed field:

var ndt:NotesDateTime = session.createDateTime("Today");
ndt.toJavaDate().toLocaleString()

but it displays the date too and i think every time I opened the doc. the date changes.

For displaying the username, I tried adding a computed label:

    if (currentDocument.isNewNote())
{return @Name("[CN]", session.getEffectiveUserName());
}

But, if I re-open the document later, of course the label value is empty, I should add in the else case something like @ThisValue from Lotus Notes.

هل كانت مفيدة؟

المحلول

apply a datetime converter to your control and set it to show time only.

Update:

Just read your last remark regarding the changing of values. Maybe you are mistaking the role of a Computedfield control in xpages with the one a computed field has within a Notes Form: in xpages the control is like a "computed for Display" field as it doesn't store values in a doc, it just displays them. In your case you might want to use a combination of a beforePageload event where you write the current date time value to the Notes field, if the datasource isNew(). Your computed field then is showing the value stored before.

Update #2:

In case you just wanted to display the time of day when the doc was first created you of course don't need to calculate and store that value in your documents. Instead just use the computedField mentioned above, then apply a ssjs version of @Created to it. Finally apply the beforementioned Datetime converter to the control.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top