w6GFr‖

bGg9p‖Defining Conditions

J8SYs‖Conditions are logical expressions that you can use to control the display of fields and sections in your document. Although the following examples apply to fields, they also apply to sections.

kFVxj‖You can define conditions for the following field types:

  1. uhYUE‖Conditional text: displays text A if the condition is true, or text B if the condition is false.

  2. i5GC7‖Hidden text: hides the contents of the field if the condition is true.

  3. DovMC‖Hidden paragraph: hides the paragraph if the condition is true.

  4. 23Bhj‖Any record and next record: controls the access to database records.

Rjj7J‖The simplest way to define a condition is to type the logical expression directly in a Condition box using the following values:

8p96j‖TRUE

jH4Z3‖The condition is always met. You can also enter any value not equal to 0 as the conditional text.

bVhKR‖FALSE

ZT8mx‖The condition is not met. You can also enter the value 0.


note

hyaBZ‖If you leave the Condition box empty, the condition is interpreted as not being met.


HyEVQ‖When you define a condition, use the same elements for defining a formula, namely comparative operators, mathematical and statistical functions, number formats, variables and constants.

xGZuG‖You can use the following types of variables when you define a condition:

  1. ChwEN‖Predefined LibreOfficeDev variables that use statistics on document properties

  2. i4seA‖Custom variables, that are a created with the "Set variable" field

  3. SSQFn‖Variables based on user data

  4. HjMGK‖Variables based on the contents of database fields

4vRCr‖You cannot use internal variables, such as page and chapter numbers, in condition expression.

8L4R9‖Conditions and Variables

7SFsW‖The following examples use a variable called "x":

JQeFL‖x == 1 or x EQ 1

JCgHz‖The condition is true if "x" is equal to 1.

EAuFn‖x != 1 or x NEQ 1

xhFp2‖The condition is true if "x" does not equal 1.

b4kQm‖sinx == 0

xNMJB‖The condition is true if "x" is a multiple of pi.


CYBa5‖To use comparative operators with strings, the operands must be bounded by double quotation marks:

48SNN‖x == "ABC" or x EQ "ABC"

CvAqA‖Checks if variable "x" contains (true) the "ABC" string, or not (false).

23iCh‖x == "" or x EQ ""

Eog2t‖or

bdkAT‖!x or NOT x

HZref‖Checks if the variable "x" contains an empty string.


note

qzHpM‖The "equal" comparative operator must be represented by two equal signs (==) in a condition. For example, if you define a variable "x" with the value of 1, you can enter the condition as x==1.


DhU9j‖User Data

Rc96U‖You can include user data when you define conditions. To change your user data, choose - LibreOfficeDev - User data. User data must be entered in the form of strings. You can query the user data with "==" (EQ), "!=" (NEQ), or "!"(NOT).

gL2nG‖The following table lists user data variables and their meanings:

NSDka‖Variable

4yzBF‖Meaning

user_firstname

Ni7UQ‖First name

user_lastname

mVhRE‖Last name

user_initials

KqDJC‖Initials

user_company

szeBa‖Company

user_street

usGfu‖Street

user_country

Mfv8d‖Country

user_zipcode

VuC8X‖Zip code

user_city

NEsBf‖City

user_title

KDQFy‖Title

user_position

dLYQP‖Position

user_tel_work

GJ5vX‖Business telephone number

user_tel_home

6hw8b‖Home telephone number

user_fax

5Uqtj‖Fax number

user_email

vxLtn‖Email address

user_state

aMV33‖State (not in all LibreOfficeDev versions)


SLUe6‖For example, to hide a paragraph, text, or a section from a user with a specific initial, such as "LM", enter the condition: user_initials=="LM".

XnrrC‖Conditions and Database Fields

V88Ua‖You can define conditions for accessing databases, or database fields. For example, you can check the contents of a database field from a condition, or use database fields in logical expressions. The following table lists a few more examples of using databases in conditions:

XTNC7‖Example

pBqA5‖Meaning

saNLv‖Database.Table.Company

Qocp5‖Database.Table.Company NEQ ""

Ps8wW‖Database.Table.Company != ""

hxQWr‖The condition is true if the COMPANY field is not empty. (In the first example, no operator is required.)

7Tb4G‖!Database.Table.Company

ezt2J‖NOT Database.Table.Company

fHiBT‖Database.Table.Company EQ ""

9aPEj‖Database.Table.Company ==""

Jnd4i‖Returns TRUE if the COMPANY field is empty.

nHKAn‖Database.Table.Company !="Sun"

vCQGw‖Database.Table.Company NEQ "Sun"

56RM2‖Returns TRUE if the current entry in the COMPANY field is not "Sun". (Exclamation sign represents a logical NOT.)

yas2m‖Database.Table.Firstname AND Database.Table.Name

JE4uA‖Returns TRUE if the record contains the first and the last name.


note

Tjk7D‖Note the difference between the boolean NOT "!" and the comparative operator not equal "!=" (NEQ).


yvMaJ‖When you refer to a database field in a condition, use the form Databasename.Tablename.Fieldname. If one of the names contains a character that is an operator, such as a minus sign (-), enclose the name in square brackets, for example, Databasename.[Table-name].Fieldname. Never use spaces inside field names.

87CGU‖Example: Hiding an Empty Database Field

mTR3d‖You may want to create a condition that hides an empty field, for example, if the COMPANY field is empty for some of the data records.

ELZaN‖Select the Hidden Paragraph list entry, and type the following condition: Addressbook.Addresses.Company EQ ""

fS9ti‖or type the following

KBQes‖NOT Addressbook.Addresses.Company

7RyrC‖If the COMPANY database field is empty, the condition is true and the paragraph is hidden.

note

BQUAo‖To display hidden paragraphs on the screen, choose - LibreOfficeDev Writer - View, and clear the Hidden paragraphs check box.


kBuFH‖Examples of Conditions in Fields

3qi9h‖The following examples use the Conditional text field, although they can be applied to any fields that can be linked to a condition. The syntax used for conditions is also used for the Hidden text, Hidden paragraph, Any record or Next record fields.

aRLQq‖To display conditional text based on the number of pages:

  1. MkG3n‖Choose Insert - Field - More Fields, and then click the Functions tab.

  2. H4iDS‖In the Type list, click "Conditional text".

  3. oQ9Es‖In the Condition box, type "page == 1".

  4. KufH3‖In the Then box, type "There is only one page".

  5. q2GJJ‖In the Or box, type "There are several pages".

  6. ScjYk‖Click Insert, and then click Close.

JyAFv‖To display conditional text based on a user-defined Variable

  1. EKqBF‖Choose Insert - Field - More Fields, and then click the Variables tab.

  2. nFZmQ‖In the Type list, click "Set Variable".

  3. BiGCY‖In the Name box, type "Profit".

  4. HCCpo‖In the Value box, type "5000".

  5. izStq‖Click Insert.

  6. Tv2EP‖Click the Functions tab, and click "Conditional text" in the Type list.

  7. MzRsU‖In the Condition box, type "Profit < 5000".

  8. XZFrE‖In the Then box, type "Target is not met".

  9. tt2tE‖In the Or box, type "Target is met".

  10. mBbvT‖Click Insert.

B6Xgd‖To edit the contents of the "Profit" variable, double-click the variable field.

dnveA‖To display conditional text based on the contents of a database field:

fTqTB‖The first part of this example inserts a space between the "First Name" and "Last Name" fields in a document, and the second part inserts text based on the contents of a field. This example requires that an address data source is registered with LibreOfficeDev.

  1. LZ4P6‖Choose Insert - Field - More Fields, and then click the Database tab.

  2. 5ANfT‖In the Type list, click "Mail merge fields".

  3. 6y4CB‖In the Database selection box, double-click an address book, click "First Name", and then click Insert. Repeat for "Last Name".

  4. EAvoR‖In the document, place the cursor between the two fields, press Space, and then return to the Fields dialog:

  5. dxP4F‖Click the Functions tab, and then click "Conditional text" in the Type list.

  6. VBTBK‖In the Condition box, type: "Addressbook.addresses.firstname".

  7. DGjxA‖In the Then box, type a space and leave the Or box blank.

HNNFU‖You can now use a condition to insert text based on the contents of the First Name field.

  1. jLGF8‖In the Fields dialog, click the Functions tab.

  2. xpBc7‖In the Type box, click "Conditional text".

  3. nLcRi‖In the Condition box, type: Addressbook.addresses.firstname == "Michael"

  4. FKcEF‖In the Then box, type "Dear".

  5. mxYM7‖In the Else box, type "Hello".

  6. HnqYR‖Click Insert.