APPLICATION DESIGN


Examples: Adding programming to columns
The following examples illustrate some common column programming techniques.

Determining text, based on a field value
In a column, you can show custom text based on a condition or on a number of conditions. For example, you can create a formula that displays custom text if sales exceed a certain amount. This formula tests the value in the Sales_February field (a number field) and displays text based on that value:

@If(Sales_February>60000;"Great month!";"")

Determining text, based on the form name
The Subject column in the All Documents view of the Mail template uses the following formula. It displays a subject line based on the form the document was created with.

@If(Form = "NonDelivery Report"; "DELIVERY FAILURE: " + FailureReason; Form = "Delivery Report"; "DELIVERED: " + Subject; Form = "Return Receipt"; "RECEIVED: " + Subject; Form = "ReturnNonReceipt"; "NOT RECEIVED: " + Subject; Subject)

Combining text and dates
You can combine text and field values in a column in a scheduling database to add an explanation about the documents. The formula below displays a text message and a date, with two variations that depend on the value in the Sched field. The "D1S0" part of the @Text formula is a formatting option that removes clutter from the view by showing the month and day portion of the date field only and omitting the exact time.

@If(Sched = "Special schedule"; "Special schedule for the week of: " + @Text(Date; "D1S0"); "My regular schedule, as of " + @Text(@Modified; "D1S0"))

Combining text and names
The following formula results in three possible results, based on the status of a request:

@If(Status="Rejected";"Rejected by " + LastApproveName; SignatureCount=0; "Original Request";"Approved by " + LastApproveName)


Showing when a document was created
The Created column in the By Author view of the Document Library template uses the following formula to display the date on which the document was created:

@Created

Expandable levels (variation on the simple function)
The simple function Collapse/Expand (+/-) uses @IsExpandable without any arguments. If you want to display a plus symbol (+) when a document has responses, but suppress a minus symbol (-) when responses are expanded, use the formula:

@IsExpandable("+";"")

Displaying two field values in one column
To show people's names and phone numbers together in one column, create a column that is sorted in ascending order (the recommended order for alphabetical listings). The following formula separates the two field values with a blank space:

Name + " " + Phone

Creating "fake" indenting
When IBM® Lotus® Notes® indents response documents, the indentation is always the same. If you want to make a document in a flat view appear indented without using response documents, or display document titles in the same column at different indentations, you can use a field on the form to determine how much each document indents and use a column formula that appends space characters to the document titles in the view. The following formula "indents" documents in three different ways depending on the value in the Indent field. For example, if the value of the Indent field is 2, Notes prepends 18 space characters to the Subject of the document in the column.

@If(Indent = 1; @Repeat(" "; 12) + Subject; Indent = 2; @Repeat(" "; 18) + Subject; @Repeat(" "; 6) + Subject)

Numbering documents
In a By Author view, the following formula numbers (as in 1., 2., 3.) each of the documents within each author's category:

@IsCategory("";@DocNumber("") + ". ")

If the row is a category (the author's name), @IsCategory returns a null string (""). If the row isn't a category, then the row represents a document, and @DocNumber returns a string that represents the entry number of the document. The document's full entry number is something like 1.1, 1.2, 1.3, and so on, but when used with the null string (""), @DocNumber returns the rightmost component of the entry number. The formula then adds a period and a space ". " after the number.

Setting column colors programmatically
In Notes client applications, you can set a column's background color and text color programmatically by selecting the "Use value as color" option on the Info tab of the Column Properties box and then supplying RGB coordinates in the Programmer's pane as the value for the column.

Note This feature is supported on the Web, but you must supply the RGB coordinates of the color as a number list (e.g. 255:0:255). Text color values (e.g. "FF00FF") are not supported.

If you specify one set of coordinates (three numbers separated by colons), the color defines the appearance of the text. If you specify two sets of coordinates (six numbers separated by colons), the first set of coordinates defines the background color for the column, and the second set of coordinates specifies the text color. The color affects the column where you set the color value and all columns to the right of that until another color is set.

Note Setting colors to -1:-1:-1 reverts to the view and column properties.

For example, the following formula example shows how RGB coordinates can be used in both single and paired sets.

red := 255:0:0;
blue := 0:0:255;
yellow := 255:255:0;
pink := 255:193:253;
white := 255:255:255;
black :=  1:1:1;
apricot := 255:155:133;
plain:= 0:0:0;

@If (category = "cats";blue:red ;subcategory = "collars";pink;subcategory  ="leashes";black:plain;0:0:0);

Note You do not need to define the color names -- you can enter the numeric combinations directly into a formula. However, defining the colors makes it easier to see what you are doing and reduces the possibility of a typing error if you are using the same color more than once. While defining the colors makes it easier for you to use words rather than number combinations, the color column sets does not display the data itself. To display the category "cats" in red, for example, you would need a subsequent column that is set to display the category.

You can also set the column value equal to a field value that supplies RGB coordinates. You can use this feature in conjunction with the color field to allow a user to set a color with a color picker. You can then apply that color to a view component -- for example to the text in a column. For information on using this feature to make view colors customizable, see "Allowing users to set colors in a view."