Manage Learn to apply best practices and optimize your operations.

Notes Item/Field size limitation

Dynamically write to multiple fields

In LotusScript, when using NotesItem AppendToTextList method to build a UNID list, the maximum number of UNIDs a NotesItem can hold is 964, which is about 30848 bits (32-bit UNID * 964). The 965th UNID that is appended will give an error of cannot append text to a null item. An actual field on a NotesDocument probably can only contain 16K, so the number of UNIDs can be put in a field is much smaller.

If you have to put more UNIDs in a field on a document, multiple fields would have to be used. A sample code of dynamically writing into multiple fields and dynamically reading from possible multiple fields shown below.

'Dynamically write to multiple fields

Dim numUnids As Integer
Dim unidArray As Variant
Dim arrayItem As NotesItem
Dim fieldNum As Integer
Dim fieldName As String
Dim i As Integer
Dim doc As NotesDocument

'set the limit of the number of UNIDs a field can contain to 400
fieldUnidsLimit = 400 

fieldNum = 1
numUnids = 0

'references is a list of UNIDs we got in memory by early processing
Forall x In references
  'count the total number of UNIDs
  numUnids = numUnids + 1
End Forall

If numUnids <= fieldUnidsLimit Then
  'the number of UNIDs need to store on the document is less than the limit 
  'use a single field-DocRefs field to hold the UNIDs
  doc.DocRefs = references
  'the number of UNIDs need to store on the document is greater than 
the limit, need to dynamically create more fields to hold the UNIDs, the field name would be used are DocRefs1, DocRefs2 ... 'Redim sets first element as index 0, so need to redim to the limit minus 1 Redim unidArray(fieldUnidsLimit-1) As String For i = 1 To numUnids 'fieldUnidsLimit*(fieldNum-1) calculates the number of Unids that have been put on the doc unidArray(i-1-fieldUnidsLimit *(fieldNum-1)) = references(i-1) If i = fieldUnidsLimit * fieldNum Or i = numUnids Then 'a field is full or we reach the end, put the array on the doc,
erase the array, and prepare for the next field fieldName = "DocRefs" & Cstr(fieldNum) Set arrayItem = doc.ReplaceItemValue(fieldName, unidArray) Call doc.Save(True, True) If i < numUnids Then 'more fields needed, increment fieldNum for next field fieldNum = fieldNum + 1 'empty the array and reDim for the next field Erase unidArray If (numUnids - i) <= fieldUnidsLimit Then Redim unidArray(numUnids - i - 1) Else Redim unidArray(fieldUnidsLimit - 1) End If End If End If Next End If '*************************** 'Dynamically read from possible multiple fields Dim fieldName As String Dim fieldNum As Integer Dim arrayItem As NotesItem If doc.DocRefs(0) <> "" Then 'this is the case there is only one field 'do operations here...... Else 'If the DocRefs is not on the doc, we know there are mutiple fields of that fieldNum = 1 fieldName = "DocRefs" & Cstr(fieldNum) While doc.HasItem(fieldName) Set arrayItem = doc.GetFirstItem(fieldName) 'do operations here...... fieldNum = fieldNum + 1 fieldName = "DocRefs" & Cstr(fieldNum) Wend End If

Dig Deeper on LotusScript



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury