0

How do you copy a datetime field from the current document to a new document in Xpages, SSJS.

I am coping other fields like this

inheritDoc.appendItemValue("AbbreviatedCustomer",currentDocument.getValue("AbbreviatedCustomer"));
var item:NotesItem = inheritDoc.replaceItemValue("Author", n1); item.setNames(true);
item = inheritDoc.replaceItemValue("AuthorAccess", currentDocument.getValue("AuthorAccess")); item.setAuthors(true);

But I do not know how to copy a date field from the currentDocument to the inheritDoc. Thanks

2 Answers2

2

You don't have to care about data types copying fields (=Items) from one document to an other if you use

inheritDoc.copyItem(currentDocument.getDocument().getFirstItem("FieldName"))

or

inheritDoc.replaceItemValue("FieldName", currentDocument.getDocument().getFirstItem("FieldName"))

Fields in target document will have same data type, content and properties as in source document.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • If i use copy item I get the following error 'getFirstItem(string)' on an object of type 'NotesXspDocument [Static Java Wrapper, com.ibm.xsp.model.domino.wrapped.DominoDocument]' if i use replaceItemValue I get Error calling method 'getFirstItem(string)' on an object of type 'NotesXspDocument [Static Java Wrapper, com.ibm.xsp.model.domino.wrapped.DominoDocument]' thanks for your help – user2478462 Jun 13 '13 at 13:20
  • @user2478462: added ".getDocument()" like you mentioned in comment. You should put "currentDocument.getDocument()" in a "var sourceDoc", use "sourceDoc" in copyItem() and recycle it at the end "sourceDoc.recycle()". – Knut Herrmann Jun 14 '13 at 04:27
0

Try using toJavaDate():

inheritDoc.replaceItemValue("DateField", currentDocument.getValue("DateField").toJavaDate());
Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76
  • You dont explicitly use the javadate. It should be enough to use the good old copyitem method. – jjtbsomhorst Jun 13 '13 at 08:07
  • using .toJavaDate()); Resulted in the following error [TypeError] Error calling method 'toJavaDate()' on an object of type 'Date [JavaScript Object]' here the line of code inheritDoc.replaceItemValue("CloaseDate",currentDocument.getValue("CloseDate").toJavaDate()); – user2478462 Jun 13 '13 at 13:06
  • The answer was given by Per and Nathan inheritDoc.copyItem(currentDocument.getDocument().getFirstItem("CloseDate")) – user2478462 Jun 13 '13 at 18:43
  • It was Paul and Nathan :-) – Per Henrik Lausten Jun 13 '13 at 18:45