Configuring the .NET Scripting Block

This section shows you how to configure, add and remove the fields in your script and to check the script for validity. See the .NET Scripting block - technical script features section for more detail on what operations and predefined functions are available for use for the script itself.

On this page you can find out about:

NOTE: CSense provides secure native blocks and operations for building analytics and solutions. The native capabilities provided by CSense can be extended by making use of this feature. When making use of this feature, please ensure that you have validated your extended functions to ensure that they perform as intended and do not introduce stability or security risks to your production system. Do not use scripts or components from untrusted sources.

Toolbar

The toolbar contains the following controls:

  • New – Create a blank script.
  • Open – Open an existing script (saved as a .txt file).
  • Save – Save the current script as a .txt file.
  • Cut – Cut the selected text.
  • Copy – Copy the selected text.
  • Paste – Paste the copied text to the current cursor position.
  • Verify Script - Checks the script for validity and shows any potential errors and warnings in the messages window.
  • Language selection – The programming language of choice (C# or VB.NET) is also selectable from a dropdown menu.

Script Editor

Your script can be entered in the script editor. When a block is opened for the first time, a default script is displayed, along with a creation date. When switching the language type before changing the script in any way, the default script will be updated to the new language. Apart from accepting any character, the script editor also supports the following shortcut keys, which includes script verification and quick access to input, output and state fields.

  • F7: Verify Script
  • Ctrl-I: List all Input Fields
  • Ctrl-S: List all State Fields
  • Ctrl-O: List all Output Fields

Messages Window

Any errors or warnings detected after verifying the script are shown below the script area. An error number, line number, and description of the error are shown here. A line may be double clicked to jump to the position in the script where the error or warning took place.

Outputs Tab

The names and types of all output fields are displayed here.

New fields can be added manually or imported. Existing fields can be exported. Output fields can be converted to state fields.

Adding fields manually

At the bottom of the tab, for each new field, enter a new field name and select a type from the combo box. Only DoubleField, StringField and IntegerField are valid types for output fields. Names must be unique among output fields and state fields. After a name has been entered, the “Add Field” button should turn green and allow you to create a new output field.

Removing fields

Select any number of fields in the list and click the red "Remove Field" button.

Importing fields

  1. Create a .csv file with field names and field types.

    • Column headers must be included at the top of the file as follows: Name,Type

    • Each line in the file must be of this form: <name>,<type>

    • Names must be unique among output fields and state fields.

    • Valid types for output fields are: DoubleField, StringField, IntegerField.

  2. At the bottom of the tab, click the "Import" icon.

  3. Browse to your newly created .csv file, select it, and click OK.

If the file you created is incorrectly formatted, or if a type you have specified is invalid, or if you have specified duplicate fields, a message will inform you of the error and the action taken.

Exporting fields

  1. At the bottom of the tab, click the "Export" icon.

  2. Browse to where you want your file to be created, specify a file name, and click OK.

Converting to state fields

Output fields can be converted to state fields. Converting an output field to a state field changes the field from an output field to a state field of the same name and type.

Converting to state fields is only possible where a name conflict does not occur.

To convert output fields to state field:

  1. Select one or more output fields.

  2. At the bottom of the Outputs tab, click the "Convert to state field" icon.

Successfully converted fields are no longer displayed on the Outputs tab. If you switch you to the State Fields tab, you can view the converted fields.

Fields that cannot be converted will remain selected in the list on the Outputs tab and a message will inform you of the error.

Inputs Tab

All Input fields are shown in this tab and cannot be created or removed. Selecting any number of input fields and then clicking on the "Create Output Fields" button, creates output fields of the same name and type as the selected input fields. A '*' button allows you to select all the input fields in the list. See the section on Technical Script Features for rules on using field names that exist in both the input fields and output fields lists.

State Fields Tab

The names and types of all state fields are displayed here.

New fields can be added manually or imported. Existing fields can be exported. State fields can be converted to output fields.

Adding fields manually

At the bottom of the tab, for each new field, enter a new field name and select a type from the combo box. Only DoubleField, StringField and IntegerField are valid types for output fields. Names must be unique among input fields, ouput fields, and state fields. After a name has been entered, the “Add Field” button should turn green and allow you to create a new output field.

At the bottom of the view, field names and types can be entered in text boxes. DoubleField, StringField and IntegerField can be selected as field types as well via the dropdown menu at the bottom of this tab. After a name and type is entered, the “Add Field” button should turn green, which allows you to add the field. If the custom field type you entered is incompatible with the script or in an unsupported language namespace, a dialog box will appear showing the error. If a field was added successfully, it means the field type is valid and ready for use in the script.

NOTE: Even if a state field type is valid in one language (e.g., C#), it does not mean it will work correctly in another (e.g., VB.NET). When switching languages, a dialog should appear, showing which fields might cause conflicts and cause the script to fail.

Removing fields

Select any number of fields in the list and click the red "Remove Field" button.

Importing fields

  1. Create a .csv file with field names and field types.

    • Column headers must be included at the top of the file as follows: Name,Type

    • Each line in the file must be of this form: <name>,<type>

    • Names must be unique among input fields, output fields, and state fields.

    • Valid types for output fields are: DoubleField, StringField, IntegerField, and any other types valid for the language you are using (C# or VB.NET).

  2. At the bottom of the tab, click the "Import" icon.

  3. Browse to your newly created .csv file, select it, and click OK.

If the file you created is incorrectly formatted, or if a type you have specified is invalid, or if you have specified duplicate fields, a message will inform you of the error and the action taken.

Exporting fields

  1. At the bottom of the tab, click the "Export" icon.

  2. Browse to where you want your file to be created, specify a file name, and click OK.

Converting to output fields

State fields can be converted to output fields. Converting a state field to an output field changes the field from a state field to an output field of the same name and type.

Converting to output fields is only possible where a name conflict does not occur, and for those state fields that are of a type that is also used for output fields.

To convert state fields to output fields:

  1. Select one or more state fields.

  2. At the bottom of the State Fields tab, click the "Convert to output field" icon.

Successfully converted fields are no longer displayed on the State Fields tab. If you switch you to the Outputs tab, you can view the converted fields.

Fields that cannot be converted will remain selected in the list on the State Fields tab and a message will inform you of the error.

Return to top


Related topics:

  

CSense 2023- Last updated: June 24,2025