Using the Sample Execute JavaScript Project

The Execute JavaScript function was added to the .Net and WPF screen elements. This enables you to easily manipulate simple and complex .Net and WPF screen elements using Java script (which is fast), and also enables you to return a value.

The sample project provided makes use of the .Net and WPF sample applications. Download the sample project and test applications here.

To use the sample Execute JavaScript project:

1. In Real-Time Designer, open the js.dproj.
2. In the Physical Objects tab, the sample project includes a NET45TestForm_x32 screen element of type NET Process) and a WpfTestApplication_x86 screen element of type WPF Process.

3. The sample includes a .NET Window (captured from the sample NET45TestForm_x32.exe application) with three captured screen elements:

DataGridView

TextBox

Button

4. The sample includes a .WPF Window (captured from the sample WpfTestApplication_x86.exe application) with two captured screen elements:

ModalWindow

TextBox

5. The sample includes five events that execute JavaScripts:

script1: Copies the entry in the Change me text box to the first cell in the data grid.

Copy
param = control.Text;
control.Parent.Parent.Controls.Find(
  "dataGridView1",
  true
)[0].Rows[0].Cells[0].Value = param;

script2: Copies the value in the Change me text box to the first cell in the data grid, and then increments the value by 100 and enters this into the next cell, and so on.  In this example, the Parameter value is specified as 100.

Copy
var cellCount = 0;
var row;
var c = Number(control.Text);
var dg = control.Parent.Parent.Controls.Find("dataGridView1", true)[0];
var rowCount = dg.Rows.Count;
for (var i = 0; i < rowCount; i++) {
  row = dg.Rows[i];
  cellCount = row.Cells.Count;
  for (var j = 0; j < cellCount; j++) {
    row.Cells[j].Value = c;
    c += param;
  }
}

height: Changes the height of Button1. The JavaScript is control.Height = param and the param value is set to 45.

wpf: This examples runs at the level of the TextBox screen element, and changes the height of the text box. The JavaScript is control.Height = param and the param value is set to 55.

wpf2: This example runs at the level of the ModalWindow, and copies the text from the editable text text box, to the cell located in the second row and second column of the grid (grids locations are zero-based). Notice that as this JavaScript example runs on the ModalWindow, and not the text box screen element, the control is found using control.FindName("<controlname> ").

Copy
var editText = control.FindName("textBox11").Text;
var row = control.FindName("dataGridLeft").Items[1];
control.FindName("dataGridLeft").Columns[param].GetCellContent(row).Text =
  editText;
return 1;

6. Click Run Main Project.

7. Click Monitor.

8. Run the .NET test application.

9. Test each of the scripts, by selecting the Business Entities tab and then setting the value of the required entity to True. For example, change the text Change me to something different, such as Hello World, and then change the value for go1 to True. This executes script attached to the script1 event handler, copying the Hello World text to the first cell in the data grid.

10. To test JavaScript manually against a screen element, select the Screen Element tab, select the required screen element and then click the Functions tab, and select Execute JavaScript from the list of Available Functions. Enter the Script and Parameter (optional) and then click Invoke.

11. Click Invoke. The function is executed.
12. Similarly, run the WPF sample application and scripts.