2
votes

I am accessing a document from a view, read a datetime field, figure out number of days between two date/time values which fall into four categories. In each category there is a for loop which add number of datetime values to an array of variant. Array entries are between seven and 35. After the loop I like to assign the array values to a date time field on the form and save the document. I have used Notes item as follow:

Dim nitem as Notesitem  
Set nitem = doc.ReplaceItemValue("Datefield", dtArray)  

It didn't work. I used doc.ReplaceItemValue "Datefield, dtArray this one didn't work either. The field is blank after the agent runs. I declared a variable and assigned the array to the variable then assigned variable to the field on the form:

Dim var1 as variant
var1 = dtArray
doc.datefield = Var1

Still no luck to see array values assigned to the field in the document

Here is main loop

Redim dateArray(0)
For i=0 to NumberofDays -1
    set notesitem = dtitem.DateTimeValue
    call notesitem.AdjustDay(i)
    set dateArray(i) = notesitem
    Redim preserve dateArray(i+1)
Next


doc.replaceitemvalue "Datefield", dateArray

call doc.save(false, true)
erase dateArray

Why after the agent runs datefield in the documents are blank? What is missing? How should I change this to get result. Is it possible to add a delemiter to the assignment statement as follows:

Thank you

3

3 Answers

1
votes

When you're playing around with NotesItem and the NotesDateTime classes, I think you will have more joy using the NotesItem DateTimeValue property. This is read / write, and returns (or expects) a NotesDateTime object.

For example, if you have a NotesDateTime instance called "dt", this is how you would write it back to a field called "YourDT":

Dim itDT as NotesItem
Dim dt as New NotesDateTime
' Instantiate itDT and dt
...
Set itDT.DateTimeValue = dt

So, you should be able to take your array of NotesDateTime objects, and write it back to the relevant field using this approach.

1
votes

The simplest way to assign dateTime field from an array is:

SimpleDateFormat smdf = new SimpleDateFormat();
smdf.applyPattern("dd.MM.yyyy");
Vector dates = new Vector();
for (Date dt: dateArray) {
       dates.addElement(smdf.formatter(dt));
}; 
doc.replaceItemValue("dateField", dates);
0
votes

This is tricky to trouble shoot for you, as you haven't provided the original source code. The way your trying to use methods is a bit strange.

Below is a basic go at what you're trying to do. DateTime fields are a bit tricky, but you can set them using variant arrays.

    Dim i As Integer
    Dim vDateArr() As Variant
    Dim itDate As notesItem
    ' setup date array.
    ' .........
    ' .........
    ' Now get the date field to be updated from the document
    Set itDate = doc.GetFirstItem("fieldName")
    ' loop through the array of values and make sure they're date time
    For i=0 To numberOfDays - 1
       ' ensure that the array has date type values. V_DATE is a constant defined 
       ' in LSConst.lss. V_DATE = 7, so you can still write the following line as
       ' If Datatype(vDateArr(i)) <> 7 then
       If Datatype(vDateArr(i)) <> V_DATE Then
           vDate = Cdat(vDateArr(i))
       End If
       vDateArr(i) = vDate
    Next
    ' assign the array back onto the itDate field. Even if the field is not 
    ' already a dateTime type. Assigning the array this way will make it so.
    itDate.Values = vDateArr
    Call doc.Save(True, False)

I find it best to work with primitives, not objects in this case. What's happening here is that I am ensuring that the date values are stored as a dateTime value. Then assigning the array to the field and then saving the document. There are a number of ways to do this, but this is my preferred way when you want to push an array of a specific type into a field. If you can post the original code, it would be easier to correct your code.