This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Feb 22, 2011, 9:38 PM
6 Posts

reading / updating notes date time item

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.1
  • Role: Developer
  • Tags: notesdatetime
  • Replies: 2
Perhaps someone can provide an explanation or provide a more correct solution..
 
Problem:  xpage button when clicks appends effectiveUserName and date to two fields which may or may not be empty.

My first stab at it looked like this:  it would read the document but saving caused a crash, no mater what.
var uname = session.getEffectiveUserName();
var fpos = @If(@Contains(currentDocument.getItemValue('Pending1'), uname), '1',@Contains(currentDocument.getItemValue('Pending2'), uname), '2','3');
var arrvalues = currentDocument.getItemValueArray('Completed' + fpos);
var dtarrvalues = currentDocument.getItemValueArray('Completed_Date' + fpos);
var dttoday = session.createDateTime(@Today());
arrvalues.push(uname);
dtarrvalues.push(dttoday.getDateOnly());
currentDocument.replaceItemValue('Completed'+fpos, arrvalues);
//currentDocument.replaceItemValue('Completed_Date'+fpos, dtarrvalues);
currentDocument.save()
After reading the developer wiki and help with my eyes open this time, I arrived here, which works whether field is empty or has values.

var uname = session.getEffectiveUserName();
var doc:NotesDocument = currentDocument.getDocument();
var fpos = @If(@Contains(doc.getItemValue('Pending1'), uname), '1',@Contains(doc.getItemValue('Pending2'), uname), '2','3');
var arrvalues = doc.getItemValue('Completed' + fpos);
var dttoday = session.createDateTime(@Today());
if (arrvalues.isEmpty()) {
doc.replaceItemValue('Completed'+fpos, uname);
doc.replaceItemValue('Comp
leted_Date'+fpos, dttoday);
} else {
var dtarrvalues:java.util.Vector = doc.getItemValueDateTimeArray("Completed_Date" + fpos);
arrvalues.addElement(uname
);
dtarrvalues.addElement(dtt
oday);
doc.replaceItemValue('Comp
leted'+fpos, arrvalues);
doc.replaceItemValue('Comp
leted_Date'+fpos, dtarrvalues);
}
doc.save();
 
any better solutions out there?
Feb 22, 2011, 10:10 PM
13 Posts
Re: reading / updating notes date time item
 you might want to use @Text around the date portions
Feb 23, 2011, 8:15 AM
261 Posts
Re: reading / updating notes date time item
How about using an "addItemValue" function that will create the item if it doesn't exist or will add a value to an existing item. The example below will work with text/date/number fields:
 
// add a value to an item on a document
function addItemValue(doc:NotesDocument, itemName:String, itemValue, allowDoubleEntries ) {
       
        allowDoubleEntries = (allowDoubleEntries || false);
       
        var item:NotesItem = doc.getFirstItem(itemName);
       
        if ( item == null ) {    //item doesn't exist
           
            doc.replaceItemValue( itemName, itemValue );
           
        } else {
           
            //add value if double entries are allowed (always) or
            //no double entries allowed and value isn't present yet
           
            if ( (!allowDoubleEntries && !item.containsValue(itemValue)) || allowDoubleEntries  ) {

                var values:java.util.Vector = item.getValues();
               
                if (values == null) {        //item doesn't have a value yet (e.g. empty string)
                   
                    doc.replaceItemValue( itemName, itemValue);
                   
                } else {
                   
                    values.add(itemValue);
                    item.setValues(values);
                   
                }
            }

        }
       
 }

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal