Custom Report Scripting

IF Command

Insert IF button The Insert IF dialogue is displayed by pressing the Insert IF button on the Control Panel.

Insert IF dialogue

The IF command was introduced in Public Talks 2010 and has added much more flexibility to the way you can process custom reports.

To learn more about the features of this dialogue, glance down the table below or highlight the control you are interested in by clicking on the screenshot above. Please also remember that context help is available to you by either pressing F1 when the control has focus, or by using the question mark icon at the top right corner of the dialogue.

For those of you who are not familiar with the concept of IF then here follows my attempt at teaching you! It allows you to introduce conditional processing in your scripts. For example:

Sample use of IF commandHere, we have placed all the script commands related to the Chairman inside an IF command. This way, the chairman value (and "Chairman:" text) will only display on the report if there is anything to display.

This will happen at certain times during the theocratic year, for example, when assemblies and conventions are held.

The uses of the IF command are virtually endless and it is up to you to determine how best to use the features provided. I have attempted to show you a variety of examples in a new sample script which you should find installed with the program. Please read the help topic about using sample scripts if required.

What follows is a detailed description of all the options available on this dialogue. It is strongly reccommended that you read this topic through in it's entirety (and optionally the IF script syntax topic). If you study this topic, along with the sample script provided, you should be well on your way in using this command. Should you still find that you are in deep waters without a paddle, then don't fret! There is a dedicated area of the support forum for custom report scripting issues.

Please note that the RowNumber field is shared among all loops at this time. If you have nested loops, RowNumber will be correct for the outside loop before the nested loop, but not afterwards; it will change to be correct for the nested loop, and thus corrupt the outside version. To work around this, if you need the row number after the nested loop then simply use VARIABLE_FIELD to save it to a variable that you can use later.

IF criteria options This option may require some explaining. It introduces the keyword NOT at the start of the criteria. Let me try and explain with an example:
Sample IF command

This IF command would cause all susequent details to display in red if the talk number was 1000.
Sample IF command (negate)

Here, we used the negate setting. This time, subsequent details are shown in red if the talk number is not 1000.

Usually you would use this facility as some kind of else clause in your scripting. Thus you don't have to make two IF commands, each equal but with logically opposite criteria. For example, the example with the Negate option set as illustrated is logically equivalent to an IF statement with the Negate option clear and with the condition “Talk Number” ISNOT “1000”. The Negate option is particularly useful if you have several criteria and you want to ensure the exact logically opposite set of criteria. OK, that was as clear as mud was it!

I will illustrate IF… THEN …ELSE in the example scripts.
Narrowing criteria Here you will see listed all of your chosen criteria parameters. You can have more than one set of criteria. However you should understand that when you do use more than one set of criteria, that all criteria must be satisfied for the IF command to be considered true.

The criteria facility works in a similar way to that used for the LOOP command.
Remove Use this button (or press the Delete key) to remove the selected criteria from the list.
flexible criteria Full details about flexible criteria are provided in the LOOP help topic.
Edit criteria Correct use of criteria is at the heart of the IF command. Using incorrect criteria is going to cause your report to display details incorrectly.

The criteria is composed from three parts:

Criteria parts1. The field (or variable) to examine
2. The type of comparison
3. The value (or variable) to use for the comparison

More details about these options and settings follow.
Criteria1 The first criteria component can be a field or a variable. The fields displayed in the droplist are those for the current row in the LOOP which contains the IF command.

The type of field you select governs how the other settings are displayed. So don't be alarmed if you see a reduced set of comparison options if you chose a date field (just as an example!).

Ticking the Variable option changes the list to show the available fields. This is a very handy facility! Also, any available options will be presented in a droplist for you if they are available. Again, I will try to show you with an example:
IF with variable

The ShowTalkNumbers variable was added to the script using the REQUIRES script command and had the VALUES set to "Yes,No".
IF variable code

Here is the matching script command. Here for example, by use of variables and the IF command we can conditionally display talk numbers in parenthesis!

Before we move on, we must bring the option $RowNumber to your attention. Can you see it in the list of available fields at the top? This is not a field but is a variable. It represents the current row number (based on the number of rows actually returned, not the size of the original table) in the LOOP. Why has this been implemented? Well, there are two reasons, one of which is describe here:

IF rowindexHere we have used the $RowNumber variable to conditionally show a label with the first row of the LOOP. Under normal circumstances you would then include more commands after the IF command. Hopefully you get the idea.
Criteria comparison The second criteria component specifies the type of comparison that you want to make. As previously stated, the available choices are dependant on the type of field that you have selected just above.

The options have been worded in a way to make it fairly intuitive what each comparison would do. Thus, by using a combination of comparisons and criteria you can limit details to a certain range. Let us say that you wanted to show the theme in bold for all home talks where the talk number was between 500 and 600 inclusive. Then you could do this:

IF range

At this point we should bring to your attention another special type of comparison which is only available when you have chosen an integer type field (eg: Talk Number or $RowNumber):

IF multiple This can be very useful when you want to cause a certain action to occur every X number of rows in the report. For example, you could force an ENDPAGE or a EOL after a certain number of rows.
Criteria 3 The third component specifies the value (or variable) that you compare against. The way you specify the value depends upon the type of field you have selected for the first criteria. For example, a date control is displayed if you had chosen a date field.

Tick the Variable option if you want to compare against a variables value. This can make your reports extremely flexible. So at document creation time, a variables value can be stated, and then it will get used in your IF command as the criteria to compare against!

There is a special variable called EmptyString that you can use with IF commands. It returns true if the nominate field value is null or empty.
Add and Update Press Add New to add the current criteria into the list.

Press Update to revise the slected criteria in the list with the current settings.
Other buttons Press the Insert button to add your IF command into the script editor at the current cursor location. This button will be called Update when you are editing an existing IF command.

Press Cancel to abort the command and return to the editor.

Press Help to display this help topic. But you know how to do that already!

Well, there you have it! Hope that this help topic has helped you to understand the power of the IF command and how to use it. Now would be a great time to look at the sample IF script mentioned earlier.