In order to bring you the best possible user experience, this site uses Javascript. If you are seeing this message, it is likely that the Javascript option in your browser is disabled. For optimal viewing of this site, please ensure that Javascript is enabled for your browser.
Login  |   On Demand  |   Home  |   qad.com




Using .NET Script Objects
.NET Script Objects make it possible to expand the functionality available in the report designer to go beyond VBScript logic. It is now possible to write custom C# (or any .NET language) classes and expose their public methods such that they can be invoked from within VBScript code blocks that execute during report rendering. This is a powerful capability that overcomes the many limitations of the VBScript language and the further limitations imposed by the report framework VBScript interpreter. Now any operation that can be written in a .NET language can be invoked dynamically by reports. This opens the door to performing file I/O, network calls, and custom data structures, for example.
To expose one or more .NET classes to be accessible as report script objects, perform the following steps:
1
Create an XML file that contains script object definitions. An example is given here (the XML file used for the QAD-provided script objects available for this release, which is already deployed):
<?xml version="1.0" encoding="utf-16"?>
<ScriptObjectsData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ScriptObjects>
<ScriptObjectData>
<Name>QAD_Map</Name>
<Assembly>QAD.Plugin.Reports.ReportFramework</Assembly>
<Class>QAD.Plugin.Reports.ReportFramework.ScriptObjects.Map</Class>
</ScriptObjectData>
<ScriptObjectData>
<Name>QAD_Map2D</Name>
<Assembly>QAD.Plugin.Reports.ReportFramework</Assembly>
<Class>QAD.Plugin.Reports.ReportFramework.ScriptObjects.Map2D</Class>
</ScriptObjectData>
<ScriptObjectData>
<Name>QAD_NumberUtil</Name>
<Assembly>QAD.Plugin.Reports.ReportFramework</Assembly>
<Class>QAD.Plugin.Reports.ReportFramework.ScriptObjects.NumberUtil</Class>
</ScriptObjectData>
</ScriptObjects>
</ScriptObjectsData>
Each .NET class to be exposed as a script object must have a <ScriptObjectData> entry. For each, specify:
Name — the name that the script object will appear with in the report designer VBScript editor.
Assembly — the name of the .NET DLL assembly in which the class’ implementation is contained (without the .dll extension).
Class — the fully namespace-qualified name of the class to expose from within the DLL.
As a naming convention, QAD-shipped script object classes will always have names that begin with a “QAD_” prefix. It is recommended that you not use this prefix when deploying your own custom script object classes, so that they do not conflict with any QAD-shipped script objects (either now or after future upgrades).
2
Deploy the XML file into a ReportScriptObjects subdirectory under any QAD .NET UI plug-in directory on the client machine (for example, C:\Program Files\QAD\QAD Enterprise Applications 2010.1 EE\plugins\qad.plugin.reports\ReportScriptObjects). The name of the XML files is arbitrary, as long as they have an .xml file extension; however, the directory name must be ReportScriptObjects.
3
Deploy the DLLs containing the .NET classes (and any dependent classes) into the same ReportScriptObjects directory as the XML. If the class is already in a DLL that is in a plug-in directory, that will also work. However, DLLs in any directories other than plug-in directories or an immediate plug-in subdirectory named ReportScriptObjects will not be accessible for script object exposure.
4
When the .NET UI is restarted on that client machine, the script objects will be dynamically loaded into the system. This can be verified by opening the Report Resource Designer program, creating a calculated field, and clicking the ellipses (“...”) button in the Text property of the field in the property grid. This will launch the VBScript editor. Click the “Fields>>” button in the lower left of this editor form, and navigate to the Script Objects sub-menu. Your class should no appear in the list of available script objects. If you do not see your script object here, then re-check the above steps, and check the client .NET UI log file for additional error information that might help troubleshoot the issue.
Note: Performing the above steps will only deploy the script objects to the client machine on which the steps are performed. To push this deployment out to all client machines, you must apply the same steps to the plug-in package archive on the home server.
Note: The report script object will expose just the public methods of the .NET class. Non-public methods will not be exposed for report designer usage.
Important: Due to various implementation details, severe performance problems result from the use of certain .NET data types as input parameters or return values of script object methods. Excellent performance is attained by using parameters of type string, bool, or object. Other types (including any numeric types) will result in poor run-time performance when that method is invoked by the report designer. This situation is easy to deal with: when writing the .NET classes that get exposed, simply use the object type for all parameters that have types other than string or bool. Internally, your method can have code to check the type and perform any necessary casting from object to the intended type.
This release of the Reporting Framework contains three Script Object classes provided by QAD:
QAD_Map — a one-dimensional map data structure that provides array-like capabilities.
QAD_Map2D — a two-dimensional map data structure that provides array-like capabilities.
QAD_NumberUtil — performs number-to-word translation and related utilities.
The following sections discuss these classes in more detail.
QAD_Map Script Object
Script Object that implements map functionality exposed in VBScript for use in report designs. The VBScript interpreter in ComponentOne reporting does not support arrays, so this is a way to provide that functionality. This implementation is a map from an integer key to a value. The values are of type object, so they can hold any type passed from VBScript. The keys are restricted to integers since ComponentOne’s VBScript interpreter cannot iterate in loops except for for-loops based on integer indices. Restricting keys to integers restricts them to a type that can be iterated over, and that avoids casting issues arising from hard-coded integers in VBScript appearing as “double” numbers in .NET (causing key lookup failures if not explicitly cast as int in .NET).
QAD_Map.Clear()
Clears map contents.

QAD_Map.Clear() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
Boolean
Clears the map contents.
QAD_Map.Contains(key)
Returns true if the map contains an element with the specified key, false otherwise.

QAD_Map.Contains(key) Parameters
 
Name
Input/Output
Data Type
Description
key
Input
Integer
Integer key of element whose existence to check for, typed as an object for better performance.
 
Return Value
Boolean
Returns true if the map contains an element with the specified key, false otherwise.
QAD_Map.ContainsValue(value)
Returns true if the map contains an element with the specified value, false otherwise.

QAD_Map.ContainsValue(value) Parameters
 
Name
Input/Output
Data Type
Description
value
Input
Integer
Value of element whose existence to check for.
 
Return Value
Boolean
Returns true if the map contains an element with the specified value, false otherwise.
QAD_Map.FindIndex(value)
Finds a key (index) corresponding to an element having the specified value. If no such element is found, then null will be returned. If more than one element is found with the value, then there is no guarantee which of their indices will be retrieved.

QAD_Map.FindIndex(value) Parameters
 
Name
Input/Output
Data Type
Description
value
Input
Integer
Value of element whose key is to be returned.
 
Return Value
Integer
Integer key of an element having the specified value, typed as an object for better performance, or null if no elements exist with the specified value.
QAD_Map.Get(key)
Gets the value of the element with the specified key.

QAD_Map.Get(key) Parameters
 
Name
Input/Output
Data Type
Description
key
Input
Integer
Integer key of element to get, typed as an object for better performance.
 
Return Value
Integer
Value of element having specified key, or null if no element exists with that key.
QAD_Map.GetCount()
Returns a count of the number of elements in the map.

QAD_Map.GetCount() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
Integer
Count, as an integer typed as an object for better performance.
QAD_Map.GetKeys()
Returns the collection of keys in the map as a comma-separated list of strings, sorted in order of key index.

QAD_Map.GetKeys() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
String
Comma-separated list of keys as strings.
QAD_Map.GetValues()
Returns the collection of values in the map as a comma-separated list of strings (each value object’s ToString() output), sorted in order of key index (not value index) so as to retain the order alignment with the GetKeys() function. Any literal commas in the value strings will be escaped by preceding with a “\”.

QAD_Map.GetValues() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
String
Comma-separated list of values as strings.
QAD_Map.Remove(key)
Removes the element with the specified key. If no such element exits, then nothing is done; no exceptions are thrown.

QAD_Map.Remove(key) Parameters
 
Name
Input/Output
Data Type
Description
key
Input
Integer
Integer key of element to remove, typed as object for better performance.
QAD_Map.Set(key, value)
Sets the element with the specified key to have the specified value. If an element already exists with the same key, then its value will be replaced by the specified value.

QAD_Map.Set(key, value) Parameters
 
Name
Input/Output
Data Type
Description
key
Input
Integer
Integer key of element to set, typed as object for better performance.
value
Input
Integer
Value of element to set.
QAD_Map.Split(stringToSplit, delimiter, startIndex)
Splits the input string into multiple strings according to the specified delimiter, and for each creates an element in the map whose value is the string, and whose key is a sequential integer starting at the specified start index. Any backslash-escaped delimiters will be treated as literals and not delimiters.

QAD_Map.Split(stringToSplit, delimiter, startIndex) Parameters
 
Name
Input/Output
Data Type
Description
stringToSplit
Input
String
String to split.
delimiter
Input
Character
Delimiter to use for splitting string.
startIndex
Input
Integer
Arbitrary start index; must be an integer but is typed as object for better performance.
 
Return Value
Integer
Integer value indicating the number of elements that the input string was split into, typed as object for better performance.
QAD_Map.Split(stringToSplit)
Splits the input delimited list of values into a string array, recognizing escaped delimiters as being preceded by backslash characters.

QAD_Map.Split(stringToSplit) Parameters
 
Name
Input/Output
Data Type
Description
stringToSplit
Input
String
String to split.
 
Return Value
Integer
Integer value indicating the number of elements that the input string was split into, typed as object for better performance.
QAD_Map2D Script Object
Script Object that implements two-dimensional map functionality exposed in VBScript for use in report designs. The VBScript interpreter in ComponentOne reporting does not support arrays, so this is a way to provide that functionality. This implementation is a map from two integer keys to a value. The values are of type object, so they can hold any type passed from VBScript. The keys are restricted to integers since ComponentOne’s VBScript interpreter cannot iterate in loops except for for-loops based on integer indices. Restricting keys to integers restricts them to a type that can be iterated over, and that avoids casting issues arising from hard-coded integers in VBScript appearing as “double” numbers in .NET (causing key lookup failures if not explicitly cast as int in .NET). This class is a direct generalization of the Map class (which is one-dimensional), and essentially provides an array of arrays, whereas if we only had the Map class, a given report would be limited to a single array.
QAD_Map2D.Clear()
Clears the entire 2-D map contents.
QAD_Map2D.Clear(key1)
Clears the contents of the 1-D map with the specified key1 value.
QAD_Map2D.Clear(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map to clear, typed as an object for better performance.
QAD_Map2D.Contains(key1)
Returns true if the 2-D map contains an 1-D map with the specified key1, false otherwise.
QAD_Map2D.Contains(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map whose existence to check for, typed as an object for better performance.
 
Return Value
Boolean
True if a 1-D map exists with the specified key1, false otherwise.
QAD_Map2D.Contains(key1, key2)
Returns true if the map contains an element with the specified key1 and key2 values, false otherwise.
QAD_Map2D.Contains(key1, key2) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element whose existence to check for, typed as an object for better performance.
key2
Input
Integer
Integer key2 of element whose existence to check for, typed as an object for better performance.
 
Return Value
Boolean
True if the map contains an element with the specified key1 and key2 values, false otherwise.
QAD_Map2D.ContainsValue(key1, value)
Returns true if the map contains an element with the specified value, false otherwise.
QAD_Map2D.ContainsValue(key1, value) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element whose existence to check for.
value
Input
Integer
Value of element whose existence to check for.
 
Return Value
 
True if the map contains an element with the specified value, false otherwise.
QAD_Map2D.FindIndex(key1, value)
Finds a key2 (index) corresponding to an element having the specified key1 and value. If no such element is found, then null will be returned. If more than one element is found with the value, then there is no guarantee which of their indices will be retrieved.
QAD_Map2D.FindIndex(key1, value) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element whose existence to check for, typed as an object for better performance.
value
Input
Integer
Value of element whose key is to be returned.
 
Return Value
Integer
Integer key2 of an element having the specified key1 and value, typed as an object for better performance, or null if no elements exist with the specified key1 and value.
QAD_Map2D.Get(key1, key2)
QAD_Map2D.Get(key1, key2) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element to get, typed as an object for better performance.
key2
Input
Integer
Integer key2 of element to get, typed as an object for better performance.
 
Return Value
Integer
Value of element having specified key1 and key2, or null if no element exists with those keys.
QAD_Map2D.GetCount()
Returns a count of the number of key1 elements in the map (that is, the number of 1-D maps that exist).
QAD_Map2D.GetCount() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
Integer
Count, as an integer typed as an object for better performance.
QAD_Map2D.GetCount(key1)
Returns a count of the number of elements in the map having the specified key1.
QAD_Map2D.GetCount(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map whose elements to count, typed as an object for better performance.
 
Return Value
Integer
Count, as an integer typed as an object for better performance.
QAD_Map2D.GetKeys()
Returns the collection of key1 values in the 2-D map as a comma-separated list of strings, sorted in order of key index.
QAD_Map2D.GetKeys() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
 
Comma-separated list of key1 values as strings.
QAD_Map2D.GetKeys(key1)
Returns the collection of key2 values in the 1-D map specified by key1, as a comma-separated list of strings, sorted in order of key index.
QAD_Map2D.GetKeys(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map whose keys to return, typed as an object for better performance.
 
Return Value
String
Comma-separated list of key2 values as strings.
QAD_Map2D.GetValues(key1)
Returns the collection of values in the 1-D map specified by key1, as a comma-separated list of strings (each value object’s ToString() output), sorted in order of key index (not value index) so as to retain the order alignment with the GetKeys() function and allow subsequently feeding the output to the Split() method to copy to another map key1.
QAD_Map2D.GetValues(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map whose values to return, typed as an object for better performance.
 
Return Value
String
Comma-separated list of values as strings.
QAD_Map2D.Remove(key1)
Removes the 1-D map with the specified key1. If no such map exits, then nothing is done; no exceptions are thrown.
QAD_Map2D.Remove(key1) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map to remove, typed as object for better performance.
QAD_Map2D.Remove(key1, key2)
Removes the element with the specified key1 and key2. If no such map exits, then nothing is done; no exceptions are thrown.
QAD_Map2D.Remove(key1, key2) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element to remove, typed as object for better performance.
key2
Input
Integer
Integer key2 of element to remove, typed as object for better performance.
QAD_Map2D.Set(key1, key2, value)
Sets the element with the specified key1 and key2 to have the specified value. If an element already exists with the same keys, then its value will be replaced by the specified value.
QAD_Map2D.Set(key1, key2, value) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of element to set, typed as object for better performance.
key2
Input
Integer
Integer key2 of element to set, typed as object for better performance.
 
Return Value
Integer
Value of element to set.
QAD_Map2D.Split(key1, stringToSplit)
Splits the input string into multiple strings using a comma delimiter, and for each creates an element in the 1-D map keyed by key1 whose value is the string, and whose key is a sequential integer starting at value 1.
QAD_Map2D.Split(key1, stringToSplit) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map to create the split elements in, typed as object for better performance.
stringToSplit
Input
String
String to split.
 
Return Value
Integer
Integer value indicating the number of elements that the input string was split into, typed as object for better performance.
QAD_Map2D.Split(key1, stringToSplit, delimiter, startIndex)
Splits the input string into multiple strings according to the specified delimiter, and for each creates an element in the 1-D map keyed by key1 whose value is the string, and whose key is a sequential integer starting at the specified start index.
QAD_Map2D.Split(key1, stringToSplit, delimiter, startIndex) Parameters
 
Name
Input/Output
Data Type
Description
key1
Input
Integer
Integer key1 of map to create the split elements in, typed as object for better performance
stringToSplit
Input
String
String to split.
delimiter
Input
Character
Delimiter to use for splitting string.
startIndex
Input
Integer
Arbitrary start index; must be an integer but is typed as object for better performance.
 
Return Value
Integer
Integer value indicating the number of elements that the input string was split into, typed as object for better performance.
QAD_NumberUtil Script Object
Script Object that implements various number conversion utilities.
QAD_NumberUtil.RoundNumber(currency, number)
Rounds a number based on the given currency’s rounding method (rounding unit and threshold).
QAD_NumberUtil.RoundNumber(currency, number) Parameters
 
Name
Input/Output
Data Type
Description
currency
Input
String
Currency upon which to base the rounding method.
number
Input
Object
Number to be rounded.
 
Return Value
Object
Returns the rounded amount.
QAD_NumberUtil.RoundNumberBaseCurrency(number)
Rounds a number based on the base currency’s rounding method.
QAD_NumberUtil.RoundNumberBaseCurrency(number) Parameters
 
Name
Input/Output
Data Type
Description
number
Input
Object
Number to be rounded.
 
Return Value
Object
Returns the rounded amount.
QAD_NumberUtil.ConvertFormat(currency, format, useZeros)
Converts the given number format string to one that properly matches the rounding method of the given currency. The useZeros variable controls whether additional decimal places are formatted with zeros (.000) or pound signs (.###).
QAD_NumberUtil.ConvertFormat(currency, format, useZeros) Parameters
 
Name
Input/Output
Data Type
Description
currency
Input
String
Currency upon which to base the conversion.
format
Input
String
Existing numeric field format.
useZeros
Input
Boolean
Specifies whether additional places are formatted with zeros or pound signs.
 
Return Value
Object
Returns a format that properly matches the rounding method of the currency.
QAD_NumberUtil.ConvertFormatBaseCurrency(format, useZeros)
Converts the given number format string to one that properly matches the rounding method of the base currency.
QAD_NumberUtil.ConvertFormatBaseCurrency(currency, format, useZeros) Parameters
 
Name
Input/Output
Data Type
Description
format
Input
String
Existing numeric field format.
useZeros
Input
Boolean
Specifies whether additional places are formatted with zeros or pound signs.
 
Return Value
Object
Returns a format that properly matches the rounding method of the currency.
QAD_NumberUtil.GetThreshold(currency)
Gets the rounding method’s threshold for the given currency.
QAD_NumberUtil.GetThreshold(currency) Parameters
 
Name
Input/Output
Data Type
Description
currency
Input
String
Specifies the currency.
 
Return Value
Object
Returns the rounding method’s threshold for the specified currency.
QAD_NumberUtil.GetThresholdBaseCurrency()
Gets the rounding method’s threshold for the base currency.
QAD_NumberUtil.GetThresholdBaseCurrency() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
Object
Returns the rounding method’s threshold for the base currency.
QAD_NumberUtil.GetRoundingUnit(currency)
Gets the rounding method’s unit for the given currency.
QAD_NumberUtil.GetRoundingUnit(currency) Parameters
 
Name
Input/Output
Data Type
Description
currency
Input
String
Specifies the currency.
 
Return Value
Object
Returns the rounding method’s unit for the specified currency.
QAD_NumberUtil.GetRoundingUnitBaseCurrency()
Gets the rounding method’s unit for the base currency.
QAD_NumberUtil.GetRoundingUnitBaseCurrency() Parameters
 
Name
Input/Output
Data Type
Description
 
Return Value
Object
Returns the rounding method’s unit for the base currency.
QAD_NumberUtil.SplitNumberLeft(number)
Returns an integer representing the portion of the input number that is to the left of the decimal point.
QAD_NumberUtil.SplitNumberLeft(number) Parameters
 
Name
Input/Output
Data Type
Description
number
Input
Integer
Input number to split.
 
Return Value
Integer
Returns an integer representing the portion of the input number that is to the left of the decimal point.
QAD_NumberUtil.SplitNumberRight(number, numDigitsAfterDecimalPoint)
Returns an integer representing the portion of the input number that is to the right of the decimal point, including only numDigitsAfterDecimalPoint places. For example, SplitNumberRight(35.1234, 2) returns 12.
QAD_NumberUtil.SplitNumberRight(number, numDigitsAfterDecimalPoint) Parameters
 
Name
Input/Output
Data Type
Description
number
Input
Integer
Input number to split
numDigitsAfter
DecimalPoint
Input
Integer
Number of digits after the decimal point to include in the returned integer.
 
Return Value
Integer
Returns an integer representing the portion of the input number that is to the right of the decimal point, including only numDigitsAfterDecimalPoint places.
QAD_NumberUtil.ToWords(number)
Converts the input number into word strings in the specified language. If there is any portion to the right of the decimal point, it will be truncated before converting. Example usage: printing the value onto a check (for example, input of 104 would result in output of “one hundred four,” in the English language).
QAD_NumberUtil.ToWords(number) Parameters
 
Name
Input/Output
Data Type
Description
number
Input
Integer
Number to convert to words.
 
Return Value
String
String representation of number in language of the report Context; throws exception if an error occurs.