Frequently Asked Questions

Q: A ComputedProperty causes the following error:

Expression cannot be evaluated in ComputedProperty 'XYZ' with ID 123
caused by: TypeError: Cannot find default value for object.
on line 21: if (v2!= undefined) { x += v2; k++}
in expression:
     1: function __f(v1, v2, v3)
     2: {
     3:     if ( v1 != undefined && v1.length > 0 ) 
                          // test for multivalued properties
     4:     {
     5:         var result = new Array();
     6:         for (var i = 0; i < v1.length; i++)
     7:         {
     8:             var x=0, k=0; 
     9:             if (v1[i] != undefined) { x += v1[i]; k++ }
    10:             if (v2[i] != undefined) { x += v2[i]; k++ }
    11:             if (v3[i] != undefined) { x += v3[i]; k++ }
    12:     
    13:             if ( k > 0) result[i] = x  / k; else result[i] = undefined;
    14:         }
    15:         return result;
    16:     }
    17:     else
    18:     {
    19:         var x =0, k=0;
    20:         if (v1!= undefined) { x += v1; k++ }
    21:         if (v2!= undefined) { x += v2; k++ }
    22:         if (v3!= undefined) { x += v3; k++ }
    23:     
    24:         return k > 0 ? (x /k): undefined;
    25:     }
    26: }
v1 = undefined
v2 =  (Array)
v3 = undefined

Answer

The parameter v2 is a multivalued variable (an array) and the Javascript statements expect a scalar value (single valued variable).


What's wrong with this script?

This Javascript function always returns true.

var NietGemaakt=0, Door=0, NietDoor=0;

if (v1 == undefined) NietGemaakt++; else if (v1 < 12) Door++; else NietDoor++; if (v2 == undefined) NietGemaakt++; else if (v2 >= 7,5) Door++; else NietDoor++;

var resultaat = Door; return resultaat;

Answer

The problem is easily solved: change the comma in 7,5 into a decimal point: 7.5.

The error is the result of a so called comma expression. The code fragment (v2>=7,5) contains two expressions, one to the left of the comma and one to the right. The left hand expression evaluates to true or false, depending on the value of v2. The right hand expression evaluates to 5. Because the code within the parentheses evaluates to the second expression, the value is '5' and as a Boolean this is true. In other words the code within the parentheses always evaluates to true.


What's wrong with this script?

var count1=0;
var count2=0;
var norm=0;
var above_norm=0;

if (v11 >= 3) count1 + (v11-3);   //A
if (v8 <3 ) count2 + (v8 - 3);    //B

if (count1 >=1 && count2 >= -2) above_norm == true;  //C

if (norm = false && v17 == 1) return 'Insufficient performance'; //D
else if (above_norm = true) return 'Excellent performance';      //E

Answer

The basic problem here is unsufficient knowledge of Javascript syntax. The problematic statements are marked as 'A', 'B', 'C', 'D' and 'E'.

Statements 'A' and 'B'
At the end of the 'if' statement there is only an a numerical expression that produces a value, but there is no assignment. I.e. neither count1 nor count2 will ever have their value changed.

Statement 'C'
This is the same problem, only the statement above_norm == true is a Boolean expression, i.e. produces the value true or false. Probably the main mistake here is not recognizing the difference between '==' and '='. The latter is the assignment operator. I.e. x = 3 + 2 means: assign the value of (3+2) to x, while x == 3 is a logical expression and tests whether x has the value 3. If so, the value of the expression is true, else it is false. But in the statement as given, there is no assignment and the value of x will not be changed.

Statement 'D'
Here the matter of confusion between '=' and '==' arises anew. In the logical part of the 'if' expression, the value false is assigned to norm and this part of the expression will get the value false. As a result the complete logical expression will always be false.

Statement 'E'
This is once more an example of confusion between '=' and '=='. above_norm = true means the value true will be assigned to above_norm and as a result the expression will always be true.

There is one more remark to add. The variables norm and above_norm are used as Boolean (logical) variables, yet they are initialized with a number. Though allowed in Javascript (it does not produce an error) this is not clear. Better it would be to initialize these variables with the logical values true or false. In this case: norm = false; and above_norm = false.


When you encounter this kind of problems, take your Javascript book and study!


How do I find a document with a specified ID

Answer: Use an XQuery in Find:

for $p in / where $p/@ID=123 return $p

How do I compute the age of a subject from the date of the assessment ('test date') and the birth date?

Answer

The assumption is that birth date and assessment date are stored in two questions with response format DateResponse. It is important to be aware that, when using a DateResponse in a JavaScript, the date value is imported as a 'long' and not as date object. So the 'long' (the number of milliseconds since january 1, 1970) must first be converted to a date object. The rest is straight forward. See the example below.


ExampleJavascriptDate.png

If the assessment date is before the birthday, age is not the difference between the year of the assessment and the year of birth but one less. In the script a provision is made for this.

(As one needs age information to apply to normtables, the hassle of a script could be avoided by asking straightforward for the age of the subject. Only one question instead of two and no script.)


How can I see the original XML passed to an XSLT template?

Answer

Place the following line in the body element of your XSLT template:

<textarea cols="150" rows="150><xsl:copy-of select="." /></textarea>

You might want to do so, if, for example, you need to debug an XSLT template. If you do, the XML source will be visible on any page that uses this template.
(For this option to be useful, you need a thorough knowledge of XML, XSLT, html and css.)


How can I send an e-mail (e.g. an invitation or an e-mail with the assessement report attached) to a group of users?

Answer

This problem can be solved with the UserProcessor. In some versions of the Bellshape system this UserAction is referred to as the ProjectProcessor.

MailviaProjectprocessor.png

The picture shows what needs to be done in order to send a mail to a group of users. In the manager screen, first select all users who have to receive the email and then click on the button of the UserProcessor.