xpages - How to store a list of dates in a multi-value field using SSJS? -
in past, i've added multi-value text data field putting values simple javascript array. example: doc.replaceitemvalue('alwaysaccess', ["john doe","bob smith"]);
any recommendations on how store series of dates in multi-value, time/date field in notes document?
tl;dr: concept should identical multi-value field of strings, date(/time) values need valid notesdatetime values stored.
a notes field can have multiple date/time values; can see in form, selecting field of type date/time , checking "allow multiple values".
you can see multi-value of replaceitemvalue page of domino designer knowledge center.
to accomplish same notesdominoapi (in ssjs), we'll need to:
- get handle on notesitem (the field, i'll create)
- create our values put in field (i'll create couple using session.createdatetime)
- add these values java.util.vector, interpreted multi-value (you should able use ssjs array, if prefer)
- set values field
sample code (i ran in onclick event of xp:button):
//create new doc var tmpdoc:notesdocument = database.createdocument(); //give form tmpdoc.replaceitemvalue("form","multidatefieldform"); //create notesitem var itm:notesitem = tmpdoc.replaceitemvalue("datefieldname",new java.util.vector()); //create vector, our multi-value container var vec:java.util.vector = new java.util.vector(); //create couple notesdatetime values store var first = session.createdatetime(new date()); vec.add(first); var second = session.createdatetime("tomorrow"); vec.add(second); //save values item itm.setvalues(vec); //save tmpdoc.save(); //recycle! first.recycle(); second.recylce(); itm.recycle(); tmpdoc.recylce();
[edit] frantisek kossuth points out in comments, sure recycle notesdomino api objects (especially date/time ones). i've updated code reflect this. [/edit]
checking form-based view after running, i'm giving (field properties reflect multi-value field of date/time values; 2 shots ran out of box).
Comments
Post a Comment