/
Script Editor

Script Editor

Intellicus provides facility to write scripts for field properties and field events using the Script Editor. This enables you to define your own constructs for report generation.

To access the Script Editor,

On the home screen from Tools Menu, click Scripting. The Script Editor – JScript screen appears.

Figure 4: Script Editor

Context-Sensitive Help

The Script Editor also provides context-sensitive help that assists in correct code (syntax) formation.

Figure 5: Context-Sensitive Help

As you enter the code in the Script Editor, the context-sensitive help keeps popping up selection list of various fields and objects that may fit into the syntax.

For example, if you enter rpt. (rpt dot), it will pop up the selection list as shown in the above screenshot.

Accessing Fields

You can access the report fields in ‘rpt.Fields’ collections. You can use this collection to write code in the Script Editor to access fields (controls) in the layout pane. Each event in the Script Editor has a specific purpose; you should not write a code that does not pertain to the object / event under which it has been written.

To add a new code under the Data Initialize event of the Intellicus Report Layout, the syntax is:

rpt.fields.add “<MyField>”;

Warning: Make sure that the added field does not already exist; else, a fatal error will occur.

Code script for the value property of the fields can be given under ‘OnFetchData’ event of Intellicus Report Layout.

rpt.fields(“SomeFieldName”).value=”<SomeValue>”;

Accessing Layout Objects

The layout objects are the controls that are added to the report layout region. [See also: Working with Layout Editor, Chapter 3], you can access these objects through control’s collection members of the sections collection.

rpt.sections(“Detail”).Controls(“imgLogo”).visible = false;

Important: You will not be able to access the database using code (scripts).

Compiling Scripts

After entering the script, you can compile the script to ensure it will run without error and you will be able to achieve the results that you want using the script.

Figure 6: Syntax Error in the script

To compile the script, click the Compile button available on Script Editor – JScript screen.

If the script has any syntax error, it is listed in a pane opening between script pane and buttons.   You can remove the errors and re-click the Compile button to make sure the script is error-free.

Find and Replace

Script Editor screen offers Find and Replace functionality.

Click  button on the toolbar of Script Editor or press Ctrl + F on the keyboard to switch on the functionality.

Figure 7: Find and Replace feature on Script Editor

You have options to search up and search down.  Selecting Match Case will conduct a case sensitive search.  Selecting Match whole word only will not find the words where the search string is part of a word.  A click on Find Next button will start search

If you want to carry out find and replace, select Find and Replace check box.  Clicking Replace will replace the next occurrence of the search sting.  Clicking Replace All will search for all the occurrences of the search string.

You can use the following objects and their properties to control the behavior of the report at runtime. These report objects are accessible in a specific hierarchy as explained below:

Figure 8: Report Object Hierarchy

The objects or events in the code editor are dependent on each other, for one object there is a specified set of events and vice-versa.

Conditional Formatting

You can achieve conditional formatting through Scripting too.

You can format a displayed row value if the values of that row satisfy a given condition. For example, if you need to compare the database field (say ‘dbfield’) with a field in the previous row, and encircle it in red if it is different, add a text box (say ‘text box’) in the report header and set its visible property (from the Properties list) as ‘False’.

Set its text property (from the Properties list) to any arbitrary value (say ‘-999’) that can never be attained by the field to be compared with.

Now, add a shape (say “shape1”) around the ‘dbfield’ and set its color and shape to a red ellipse. The same can be achieved using the Script Editor as follows:

  1. On the Desktop Studio screen, from Tools menu, click Scripting.

  2. Select object as Detail.

  3. Select event as OnFormat.

  4. Enter the following JavaScript:

Object: Detail            Event: OnFormat

Code:

function OnFormat()

{

if ( ( rpt.Section(“ReportHeader”).Controls(“txtBox”).text != “_99999” ) &&

( rpt.Fields(“dbValue”).value != rpt.Sections(“PageHeader”).Controls(“txtBox”).text ) )

{

rpt.Sections(“Detail”).Controls(“Shape1”).visible = true ;

}

else

{

rpt.Sections(“Detail”).Controls(“Shape1”).visible = false ;

}

 

rpt.Sections(“PageHeader”).Controls(“txtBox”).text = rpt.Fields(“dbField”).value;

}

Conditional Suppressing Of Rows

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

  • 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

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, write a JavaScript in the Script Editor as:

Object: Report            Event: OnDataInitialize,

Code:

function OnDataInitialize()
{
rpt.Fields.add(“valueA”);
rpt.Fields.add(“valueB”);
rpt.Fields.(“valueA”).value = 0;
rpt.Fields.(“valueB”).value = 0;
}

function OnFetchData(eof)
{
if ( rpt.Fields(“accType”).value == “A” )
{
rpt.Fields.(“valueA”).value =       parseFloat(rpt.Fields.(“valueA”).value)) + rpt.Fields(“Amt”).value;      }
else
{
rpt.Fields.(“valueB”).value = parseFloat(rpt.Fields.(“valueB”).value)) + rpt.Fields(“Amt”).value;
}

rpt.Sections(“gfDEPT”).Controls(“txtACC_A”).dataValue = rpt.Fields.(“valueA”).value;
rpt.Sections(“gfDEPT”).Controls(“txtACC_B”).dataValue = rpt.Fields.(“valueB”).value;
}

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.