Home > Domino Tips > Developer > Domino > Treating multiple fields with the same name
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DOMINO

Treating multiple fields with the same name


Paul Ivanov
11.04.2003
Rating: -3.71- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Probably every developer read the description of RemoveItem method of the NotesDocument object in Domino Designer Help with a little confusion:
If more than one item has itemName$, all items with this name are deleted.
Well, but what can they be, those multiple instances of the same item? And how can I access them individually?

In the document properties, one can see that each instance of a field with the same name has a unique Dup Item ID, starting from 0. However, there are no documented methods to programmatically use that information. Any time the item's value is invoked, it is taken from the instance with the lowest Dup Item ID, even if you try to use the Values or Text property of the NotesItem class.

The obvious idea of simply looking through all the items in the document and collecting values for repeated names in an array just won't work, since all you get is the same value (that of the zero Dup Item ID item) repeated several times. This is a clear indication that Notes/Domino is NOT an object-oriented system. The only method that discriminates between item instances is Remove of NotesItem class. Below, see an example of how the multiple Received fields can be combined in a single field, to be displayed on the memo form. Just replace the standard QueryOpen script on the Memo form (as well as Reply, etc.) with the script below, and you'll get all the Received fields combined in a single multi-valued field (the complete message trace) that can easily be shown on the form (e.g., for debug).

If you use the code below, do not forget to open the mailbox database properties and check the box "Do not mark modified documents as unread" in the design pane.

Code

Sub Queryopen(Source As 
Notesuidocument, Mode As Integer, 
Isnewdoc As Variant, Continue As Variant) 
        Set cMemoObject = 
New UIMemoDocument 
        Call cMemoObject.Init
(Source,Isnewdoc) 
        
        Set doc = Source.Document 
        If doc Is Nothing Then Exit Sub 
        Set db = doc.ParentDatabase 
        '--- if the current user cannot 
edit documents, do nothing 
        '--- (this is necessary since 
the right to read mail can be delegated) 
        If db.CurrentaccessLevel<4 
Then Exit Sub 
        s = "" 
        Do 
                f = False 
                its = doc.Items 
                Forall i In its 
                        '--- if the item name is 
"Received", prepend its value to the 
accumulator string 
                        If i.Name="Received" Then 
                                '--- the following 
check is necessary to properly
 treat newly created documents 
                                If i.Text<>"" Then 
                                        x =
Evaluate ({@Implode(Received; @Char(10))}, doc) If s="" Then s = x(0) Else s = x(0)+Chr(10)+s '--- after the item with DupItemID=0 is removed, the values of DupItemID for remaining items '--- are decremented by 1 and the item with DupItemID formerly equal to 1 becomes active i.Remove f = True Goto Skip End If End If End Forall Skip: Loop Until Not f If s<>"" Then doc.Received = s ' the formula in Evaluate converts the field into a text list, with a little formatting for readability doc.Received = Evaluate({ @ReplaceSubstring(@Explode(Received; @Char(10)); " ":@Char(9); " ")}, doc) doc.Save True, False End If End Sub

Do you have comments on this tip? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Domino
Mimic Lotus Notes Domino application functionality on the Web
A single form to view and edit any Lotus Notes document
DECS and DCR external data access considerations
How to create non-scrolling Lotus Domino view headers on the Web
Disabling the 'Submit' button on a form
An easier way to update a rich text field
Results from Default Notes Search have # of responses in brackets
Lotus Notes/Domino veteran offers comprehensive list of app dev tools
Notes to XML. . .and back again
Creating thumbnail images using LS2J in LotusScript

Lotus Domino Designer
Setting up a Domino 8.5 XPages example
An introduction to using XPages in Domino 8.5
Top 10 Lotus Notes/Domino coding and development tips of 2008
'Customize this view' options are disabled in Lotus Notes databases
Stop response documents from showing in a Lotus Notes form
Set a value in a field existing in another Lotus Notes database
Display Lotus Notes fields as separate entries in one column
An introduction to Lotus Domino Designer
Modifying LotusScript code for date and time handling
Creating custom Lotus Notes Domino login forms

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts