When dealing with strings in QIE, consideration should be given to the difference between a Java String and a JavaScript String.
QIE is a Java based application so all of the functions are executed on the back end using Java. However, all of the customized scripts written in the front end of QIE are written in JavaScript. This means that when you call any of the built-in QIE functions that return a “String” ( like message.getNode()), the “String” value that is returned is a Java string because the function is executed on the server side or back end.
You can run into problems when you try to use a Java String as a JavaScript String or vice versa. You can also run into problems when comparing values, as in an ‘if’ statement, if the comparison that is being used does not take into consideration that the values might not be the same type.
To convert a Java String to a JavaScript String you just need to add the + ‘’ The plus symbol is a JavaScript concatenation operator and the double single quotes are just an empty string value. You can actually append any string value (in-between the double single quotes) using the JavaScript concatenation operator and the result is a JavaScript String.
So to convert a Java String to a JavaScript String you can do any of the following:
var jsString = javaString + ’’;
Below is an example where the code block inside the if statement would never get executed because the patient variable is a Java String and "Self" is a JavaScript String and the two comparisons will never match because of the variable type.
var patient = source.getNode('IN1-17');
if (patient === 'self') {
This code will never execute even if both variables values are the same.
}
To fix this issue we just need to convert the patient variable to a JavaScript string by adding the + ''
var patient = source.getNode('IN1-17') + '';
if (patient === 'self') {
This code will execute when the two variables values match.
}