User Tools

Site Tools


datasourceconnectionsinmistudio

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
datasourceconnectionsinmistudio [2024/02/23 14:11] – [Sending Data to manupulator Inputs] amywdatasourceconnectionsinmistudio [2024/02/23 16:50] (current) – [Debugging JavaScript] amyw
Line 162: Line 162:
 </code> </code>
  
-// assume there is a "test.sqlite" database, and a table called "test", the column is "TheTestValue". +assume there is a "test.sqlite" database, and a table called "test", the column is "TheTestValue". 
  
 <code> <code>
Line 190: Line 190:
  
 === Debugging JavaScript === === Debugging JavaScript ===
 +
 +When you trigger the JavaScript bean to start its script, you can easily determine whether a mistake has been made in the JavaScript program because the connection line between the trigger data source and the JavaScript bean will be red. If it was successful, the line would be green. This does not mean that your program is correct, but that there were no errors.
 +
 +If the connection line is red, select the connection and look at the description line at the bottom of the Diagram Window to get some information about the problem.
 +
 +**Syntax Errors**
 +
 +The script is interpreted in two passes. The first pass checks the syntax of the program lines (does not try to evaluate any statements). In this pass, the script will stop immediately if there is an error and produce an error line that has "SyntaxError:" with a short message and a line number in it, such as: <code>"SyntaxError: missing ( before condition (JavaScript1; line 35)"</code>
 +
 +You have to go to the 35th line in the JavaScript code and find that you forgot to enclose a boolean condition statement with parentheses. Sometimes it is easier to find the nth line in the code by copying the JavaScript into a text editor that will display line numbers.
 +
 +Another common syntax error is forgetting a quote on a String. If you see 
 +<code> "SyntaxError: unterminated string literal (JavaScript; line 12)"</code>
 +look on line 12 of the script and make sure you have quotes around the string in the line. For example, 
 +
 +<code> sql="SELECT "+ mno + " from table1); needs to be changed to sql="SELECT "+ mno + " from table1");</code>
 +
 +**Execution Errors**
 +
 +Once the interpreter gets past the syntax check, it will try to execute the code, top down. Functions are not evaluated until called. Typical errors at this stage do not tell you any line numbers. Here are some examples and causes.
 +
 +
 +**TypeError: Cannot convert null to an object**
 +
 +<code> JavaScript Error: Internal Error: TypeError: Cannot convert null to an object.</code>
 +
 +When you get a "Cannot convert null to an object" this means you have referenced something in the Javascript that is not a server or manipulator in the Diagram Window logic. Look for mistakes such as:
 +
 +  1. Referencing graphical objects
 +
 +<code> source = Button->getLongValue();</code>
 +
 +This will cause an error because "Button" is a graphical object (a Button on the Design Window). Do not reference graphical objects in the JavaScript, even if you copy its icon to the Diagram Window. The way to get the value from the Button in JavaScript is to connect a Broadcast Server to the output of the Button and reference the Broadcast Server in the script.
 +
 +  2. Referencing beans that do not exist (wrong name)
 +
 +<code> MyServer -> getValueObject();</code>
 +
 +if there is no logic component named "MyServer" in the logic, or it is on a different screen, or if you mistype the name (look for upper vs. lower case in the server name). Unfortunately the error message does not indicate what name is null (does not exist) so you will need to look at your JavaScript carefully to find the problem.
 +
 +
 +**TypeError: undefined is not a function**
 +
 +This error will say 
 +
 +<code> "JavaScript Error: Internal Error: TypeError: undefined is not a function."</code>
 +
 +This will happen if you are calling a server method such as <code> myServer->getValueObject()</code> and you mistype the method name or if the method does not exist for the bean. For example, this will cause an error:
 +
 +<code>
 +Ivo = IncrementServer->getLongValue();
 +test = lvo.getLength();
 +</code>
 +
 +because getLength() does not exist as a method for a Value Object.
 +
 +Unfortunately for this error there is no indication of what the faulty method name is so you have to study your JavaScript carefully to see the problem.
 +
 +**ReferenceError: "myVariable" is not defined**
 +
 +If you reference a variable that does exit you will get an 
 +<code> "Internal Error: ReferenceError: "myVariable" is not defined." error </code> 
 +
 +For example, if your code says:
 +
 +<code>
 +vo = new StringValueObject(stateString);
 +</code>
 +
 +and the variable "stateString" has not been defined yet or is misspelled, the error will say:
 +<code>"Internal Error: ReferenceError: "stateString" is not defined."</code>
 +
 + Define "stateString" with a statement such as:
 +<code>
 +stateString = CombineStrings -> getStringValue();
 +</code>
 +
 +or
 +
 +<code>
 +stateString = "Hello";
 +</code>
 +
 +**ReferenceError: "functionName" is not defined**
 +
 +This error is caused by referencing a defined function called "functionName" that does not exist. It will say something like: "JavaScript Error: Internal Error: ReferenceError: "functionName" is not defined". This will happen if you are using a function called "functionName" and you have not defined it in the JavaScript, or if you have misspelled the function name.
 +
 +
 +((**A DataSourceConnections.frx file is attached for you to download and add to your applications directory. You could open the DataSourceConnections application to see the examples. The Design Window has descriptions and the Diagram window is the place to see all the connections and data flows.**
 + ))
 +
  
  
datasourceconnectionsinmistudio.1708715493.txt.gz · Last modified: by amyw

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki