Using Conditions
Conditions are used in conditional formatting and notifications. You need to create a condition before it can be used. All the activities regarding setting up different conditions are carried out from Conditions screen.
On the Desktop Studio screen, click button on the toolbar.
OROn the Desktop Studio screen, from Tools menu, click Conditions. The Conditions screen appears.
Figure 6: Conditions screen
You can perform the following actions:
Action | Comments |
Add | To add a condition on the report |
Modify | To modify the selected condition |
Delete | To delete the selected condition |
Import | To import an existing condition |
Export | To export a newly created condition |
OK | Saves all the changes made to the condition |
Cancel | Close screen without making changes to the report |
To create a new condition
On the Conditions screen,
Click Add The New Condition screen appears.
Figure 7: New Condition screen
In Name, specify a unique name for the condition being designed.
In Expression, specify the formula followed by an ‘=’ sign and specify expression for the field. Refer to the section ‘Expressions’ below.
Click Compile button to check the formula for syntax errors.
Click OK to save the save the created condition. The newly designed condition appears in the list on the Conditions
To modify a condition
On Conditions screen, select the condition that you want to modify.
Click Modify The Modify Condition Expression screen appears.
Edit/modify the required details.
Click OK to save the changes.
To delete a condition
On Conditions screen, click the condition that you want to delete.
Click Delete The message, “You are trying to delete the selected item. Are you sure?” appears.
Click OK to delete the condition.
Expressions
Following are the expressions:
Use this operator | To indicate this |
&& | And |
|| | Or |
! | Not |
== | Equal to |
!= | Not equal to |
< | Less than |
> | Greater than |
<= | Less than equal to |
>= | Greater than equal to |
|| | Or |
! | Not |
To use a text for checking, enclose the text within single quotes, for example: E_Name==’Pinto’.
To use a date for checking, specify the date in yyyy-mm-dd format and enclose it within single quotes, for example: JoiningDate==’2004-05-30’.
Numbers can be used as it is, for example, Sales>5000.
If a field of one type is checked with that of another type, then the conditional format will not be applied.
Examples:
if ( empno > 7500) {return true} else {return false}
if ( Sal > 7500) {return true} else {return false}
if (CustNo == ‘Elsa’){return true}
if (ename == ‘Elsa’){return true}
if (empno > 7500 || ename != ‘SMITH’ ) {return true}
if ((sal > 1400 || empno >7500) && (comm > 2)) return true
Conditional Suppressing of Rows through Scripting
You can suppress the display of certain rows as per your requirement, like some column containing NULL values can be suppressed (hidden) from getting displayed on the report.
There are two methods to do this:
Select the control and set the visible property (Property window) value as false, and assign a 0 (Zero) value to the height property (Property window) of the control.
On the Desktop Studio screen, from Tools menu, click Scripting. Select the object as Detail and the event as OnFormat.
Enter the following code:
Object: Detail Event: OnFormat
Code:
function OnFormat()
{
if ( rpt.Fields(“Name”).value == null )
{
rpt.Sections(“Details”).visible = false;
}
else
{
rpt.Sections(“Details”).visible = true;
}
if ( rpt.Fields(“Name”).value == null )
{
rpt.Sections(“Details”).height = 0;
}
else
{
rpt.sections(“Details”).height = 285;
}
}
Important: To dynamically change the height of a section through a program, the ‘CanGrow property (Properties list) of Detail Section should be set to ‘False’.
If it is set to ‘True’, then the report section will override your (height) value to adjust the height of the section.
Conditional Calculation through Scripting
You can calculate values in the report by giving conditions for calculation. For example, there are two fields in a report Account_type and Amount. There can be two account types say ‘A’ and ‘B’. If you want to sum ‘A’ and ‘B’ separately, enter a JavaScript in the Script Editor as:
Object: Report Event: OnDataInitialize,
Code:
function OnDataInitialize()
{
rpt.Fields.add(“valueA”);
rpt.Fields.add(“valueB”);
}
function OnFetchData(eof)
{
if ( rpt.Fields(“STATUS”).value == “A” )
{
rpt.Fields.(“valueA”).value = rpt.Fields(“CUST_NO”).value
rpt.Fields(valueB”).value = 0;
}
else
{
rpt.Fields(“valueB”).value = rpt.Fields(“CUST_NO”).value;
rpt.Fields(“valueA”).value = 0 ;
}
rpt.Sections(“Detail”).Controls(“extTYPE”).dataField=”valueA”;
rpt.Sections(“Detail”).Controls(“txtORDER_NO”).dataField = “valueB”;
}
This script will add two new fields in the report containing summated values for ‘A’ and ‘B’ account types.
Related content
Copyright Kyvos, Inc. All rights reserved.