Basics of JavaScript

Basic Code

Symbol Meaning
== equals
!= not equals
|| or
&& and
> greater than
>= greater than or equal to
< less than
<= less than or equal to
() brackets control order of execution
. a period indicates a property of something
Case JavaScript is case-sensitive (i.e. capitalization matters!)

Answer Variable

Any item that's been completed by a patient has 2 useful properties:

  1. Response value ("r")
  2. Point value ("p")

Accessing an Item's own Response Value

An item's own response value can be inserted into the caption or custom note of an item by using the string "$$". This is particularly useful when working with formula fields.


myPainScale, a numeric scale with point values from 0-5.

Returns the value associated with the patient's choice (always in standard language, i.e. English)
Returns the point value as a number
Returns the response value of that item when used in its own "Caption" or "Custom Note" fields (example caption field: "My Pain Scale Score: $$")

Script Variables

Variable Description Example Expressions
pt The ScriptPatient object with age, sex, etc.
pt.isMale() && pt.getAge() >= 55

Refer to "ScriptPatient Functions" for more details about more "pt." expressions.

daysSinceLastCompleted The number of day since the patient last complete this form
daysSinceLastCompleted > 365
firstTime Whether or not the patient has ever completed this form
lastCompletedTag A string “remembered” by the form last time it was completed
lastCompletedTag.indexOf('myString') != -1

ScriptUtil Functions

ScriptUtil provides miscellaneous functions that allow you to simplify your scripts and support special use-cases. ScriptUtil is bound to all script session contexts, so you can use these functions in tablet rules or within eForms (show if, make note if, etc.)

Please refer to "ScriptUtil Functions" for examples of common ScriptUtil functions.

Have more questions? Submit a request