25
Thu, Apr
0 New Articles

How to Use Lotus Notes' Multivalue Fields

Collaboration & Messaging
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Mention the idea of placing more than one value in a field to a relational database programmer and you might get a negative response like, “Are you crazy?” After all, in the rules of normalization, storing multiple values in a field is simply not allowed. Of course, Lotus Notes’ proprietary database system isn’t relational, so you don’t need to worry too much about following the rules of normalization. With Notes, you’ll spend less time dealing with the rules of normalization, which should allow you to develop the application faster and possibly free up more time to design a better application for the user. Now, that is not to say that the transaction scalability of the application will be as good as a relational database system. In general, Notes applications don’t require large transaction
volumes—and that is the assumption taken here. The bottom line is Notes will allow you to create applications quickly and easily, and multivalue fields contribute to that speed and ease. But, you will need to understand what multivalue fields are and how to use them (from a user and developer perspective) to get the most from them. The purpose of this article is to show you how to use and program multivalue fields. (Please note that some user and designer knowledge of Notes is assumed.)

The Basics of Using Multivalue Fields

A multivalue field is one that may contain a list of values. In Notes, the field will always be of a certain type such as Text, Number, or Date. Except for the Rich Text, ComboBox, Password, and Radio Button field types (which allow only one choice), all Notes field types can contain multivalues. You could think of a Notes multivalue field as an array, but much easier to use than an array when it comes to processing and displaying its values.

The designer of an application indicates that a field is a multivalue field by checking the Allow multiple values property on the Basics tab of the field properties dialog. (You access the property dialog for a field by right-clicking on the field when you’re in design mode.)

For a user to enter multiple values in a field, requires the user to indicate an additional value by keying a separator character before keying the new value. For example, in text fields, a user can append a new value to the existing values by placing a comma (,) or semicolon (;) between the previous value and the new value. The text value of “This is phrase one, this is phrase two” entered into a multivalue text field would be considered as two values: “This is phrase one” and “this is phrase two” since a comma was used to


separate the values. Notice that spaces in multivalue text fields are not considered as separators. With numeric fields, you can separate values with a comma or semicolon, or additionally, a space. For example, 1 2 3 4 5 entered into a multivalue numeric field will create a number list containing five values.

Now, using separator characters to enter multivalues is one thing; displaying multivalue is another. You see, Notes doesn’t necessarily display the separator character keyed at data entry time by the user. Notes has a number of options for the separator character that will be used to display or print a multivalue field on a Notes form (the electronic representation of a document). Valid separator character values specified by a developer for displaying multivalue fields are Space, Comma, Semicolon, New Line, and Blank Line. Semicolon is the default separator character. The number list mentioned in the previous paragraph by default would appear as 1; 2; 3; 4; 5 when displayed, no matter what separator character was used to separate the number at data entry time. The separator character used for displaying a multivalue field can be changed. To make the change, use the Display Separate Values With property of the field (found on the Advanced tab—the one with the propeller beanie of the field properties dialog) to select the separator of your choice.

When multivalue fields are used in a Notes view (somewhat similar to a spreadsheet) column, the view column will contain all values of the field separated by a comma or any other valid separator character specified by the developer. That is the case as long as the view column has enough horizontal or vertical space to display all the values.

In a view column, you have choices as to how multivalues are separated and displayed. The default separator character value for a view column is None, which causes the values to be separated with a comma. It’s the same as if you were to specify a comma as the separator character. The valid separator character values a developer can specify for view columns are None, Space, Comma, Semicolon, and New Line. Choosing the New Line value will cause a line break in the view column for each value contained in the list. The result will be a vertical stack of values. However, if you use this option, be sure to specify that your view is to display more than one line per row (the Lines Per Row view property). Nine rows are the maximum number of lines you can display per view row on Notes clients. This limit does not exist, however, on the Web interface. In fact, the Line Per Row property has no effect on the Web interface.

If you sort a column in a view containing a multivalue field and you specify the sort type as Categorized, Notes will create a separate row for each value in the field. In other words, the document will appear in the view multiple times as if the database contained more documents than it actually does. For example, a Notes document contains a color option field named ColorOptions containing three values (i.e., Red, Green, and Blue). If the column is sorted and the sort type is specified as Categorized, the view will contain three rows for what is essentially one document. Figure 1 illustrates a view similar to the one just described. A single document categorized by its multivalue ColorOptions field, containing values Red, Green, and Blue, causes three rows to be displayed.

Multivalue Field Programming Searching and Retrieving

You can programmatically search for a value in a multivalue field using the @Contains function of the Notes formula language. For example, if the ColorOptions field contains three values (Green, Black, and Red), the following expression would return the value Red:

@If(@Contains(ColorOption;"Red")
"Red”;“Red not found”)

If Red was not in the ColorOptions field, the expression would return Red not found. You can determine the number of items in a multivalue field with the @Element


function. For example, the following expression will return the value 3 for the ColorOptions field mentioned in the previous paragraph.

@Elements(ColorOptions)

You can retrieve a subset of a multivalue field with the @Subset function. For example, using the same ColorOptions field, the following expression will return the values Green and Black:

@Subset(ColorOptions;2)

The second parameter value of 2 indicates that you want the first two values of the list starting from the left.

Using the same ColorOption field, this expression will return Black and Red.

@Subset(ColorOption,-2)

The second parameter value of -2 indicates that you want the last two values of the list starting from the right.

For more powerful programming, you can use LotusScript to search for values in a multivalue field. (Note that, in all of the LotusScript examples in this article, I’m working with the back-end database and not the front-end user interface.) For example, the following LotusScript code uses the Contains method (somewhat similar to the @Contains function used earlier) of the NotesItem class to determine if the value of “Preferred” is contained in a multivalue field named Type.

Dim item as NotesItem
Set item = GetFirstItem(“Type”)

If item.Contains(“Preferred”) Then

PreferredCtr = PreferredCtr + 1

Else

NonPreferredCtr = NonPreferredCtr + 1

End If

The next example accomplishes the same thing but uses a simple comparison in a looping technique instead of the Contains method.

Dim MultiValue as Variant
MultiValue = doc.GetItemValue(“Type”)
Forall v in MultiValue

If v = “Preferred” Then

PreferredCtr = PreferredCtr + 1

Else

NonPreferredCtr = NonPreferredCtr + 1

Endif
End forall

When using the GetItemValue method (as I’ve done in the previous code segment), it’s important to remember to define the receiving variable as type Variant.

Loading and Updating

You can programmatically load a value into a multivalue field using the Notes formula language @SetField function as illustrated here:

@SetField(“Products”;Product: NextProduct)


In the Notes formula language, the colon (:) is used as a list separator. So, here the value of the Product field (a field that may contain one or more values) and the value of the NextProduct field (also a field that may contain one or more values) are combined to form a list. The list is then used to set the value of Products.

To add a value to a multivalue text field with LotusScript, you can use the AppendToTextList method of the NotesItem class. For example, the following code, which is executed from a form button, will add the value of “Purple” to the multivalue field ColorOptions:

Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim item As NotesItem
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
Set item = doc.GetFirstItem(“ColorOptions”)
Call item.AppendToTextList(“Purple”)

To replace the values of a multivalue field with an entirely new list of values, you could use code similar to the following:

Dim NewVals (1 to 3) as String
Dim item as NotesItem
... set value of doc
Set item = doc.ReplaceItemValue( “ColorOptions”, Null)
NewVals(1) = “Purple”

NewVals(2) = “Green”
NewVals(3) = “Blue”
Call item.AppendToTextList(NewVals)

Since I want to replace values, I start by replacing the value of the ColorOptions field with Null, so the field is empty. The next three statements load the NewVals string array with three color values. The last statement appends the NewVal array (essentially, a multivalue list) to the ColorOptions field.

Displaying Multiple Values on Separate Lines on a Form

If you find you want to display the values of a multivalue field on separate lines in a Form, you can do so by implementing the following. Create a Computed For Display field whose value is obtained from the multivalue field (its Value property contains the multivalue field name). Use the property dialog for the field you just created to assign these properties: check the Allow multiple values property on the Basics tab and on the Advanced tab specify New Line as the value for the Display Separate Values property. As an option to using New Line, you could specify Blank Line, which would place an extra blank line between each value.

You can use this same technique to display computed multiple values. For example, you could use the @DbLookup function to compute a multivalue list by retrieving a column value from a view. The following expression could be used as the value for a Computed For Display field as described in the previous paragraph.

@DbLookup(“”:“NoCache”; servername : dbname;“Products”; UniqueID; 3);

This function returns the value of column three of the Products view for every row of data in the view where column one (the first sorted column of the view) matches the key


value in UniqueID field. Assuming more than one row matches the key, the system would return a multivalue list.

Stacking a Computed Multivalue List in a View

Assume you want to stack a customer’s address vertically in a Notes view row by using the New Line technique described earlier. However, the address isn’t stored in a multivalue field—it’s stored in six separate single-value fields. What you can do is create a multivalue list on the fly by concatenating the single value fields into a text list using the colon character.

Here is the expression for the view column:

Addr1 : Addr2 : Addr3 :
@Implode(City + " " +
State + " " + Zip)

What I’m doing here is building a list and a text string from the six address fields. I’m concatenating City, State, and Zip (including a space in between) because I want those three fields on the same line. I’m using the @Implode function because I want the system to treat the City, State, and Zip fields as a text string, not a text list. If I removed the @Implode function, the system would treat City, State, and Zip as a text list and concatenate the values of State and Zip to the value of fields Addr1, Addr2, Addr3, and City.

Figure 2 (page 61) illustrates a view that uses the technique I just described.

Go Ahead. Break the Rules!

Notes multivalue fields allow you to break relational database rules, so you can create applications much more quickly. Hopefully, you’ve learned enough here to start using multivalue fields in Notes. I think you’ll find you can build applications in Notes more quickly than you ever thought possible with a relational database system.

Figure 1: If categorized in a Notes view, a document field containing multiple values will be displayed multiple times—once for each value in the field.


How_to_Use_Lotus_Notes__Multivalue_Fields05-00.png 445x230

How_to_Use_Lotus_Notes__Multivalue_Fields06-00.png 445x498

Figure 2: The values in the Address column are derived from a computed text list and stacked vertically by specifying New Line as the separator character in the column properties.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: