logMsg()
Get specific information regarding a rule's logic while debugging. Place log statements where needed in the JavaScript expression to display values of defined variables and messages to reveal a rule's behavior.
Syntax
logMsg(argument)
Parameters
Return value
The argument passed to the logMsg()
helper function
will be returned and displayed in the log window when debugging.
Usage tips
Note:
Since thelogMsg()
helper function only runs in debug mode, there is no need to remove the calls before
publishing the rule.
Example 3-81 Using labels for variables
Use labels when logging variables to make the output easier to follow.
logMsg("weight: "+weight); // logs the label and the variable value
Output in the log window
weight: 160
Example 3-82 Using log statements to debug rule logic
Log messages as flags to reveal the logic driving the rule's behavior.
var weight = "All visits"."Form Demo"."item weight";
logMsg("weight: "+weight); // logs the label and the variable value
if(weight >160){
logMsg("weight > 160"); // log the execution path for "if" return false; }
else{
logMsg("NOT weight > 160"); // log the execution path for "else" return true;}
Output in the log window
weight: 160
NOT weight > 160
Example 3-83 Using stringify()
method to pass
objects
Use
stringify()
method to parse objects to strings, so they can be
used in log statements.
var val1 = getValues("dt1","tpt");
logMsg("dt1 = "+JSON.stringify(dt1));
Output
in the Log
Windowdt1 =
[{"visitName":"SCR","deleted":false,"tableRowInstance":null,"branchName":null,"eventType":"ScreeningVisit","formRepeatNumber":1,
"value":"2022-03-09T00:00:00.000Z","cycleNumber":null,"empty":false,"treatmentArm":null},
{"visitName":"SCR","deleted":false,"tableRowInstance":null,"branchName":null,"eventType":"ScreeningVisit","formRepeatNumber":2,
"value":"2022-03-09T00:02:00.000Z","cycleNumber":null,"empty":false,"treatmentArm":null},
{"visitName":"SCR","deleted":false,"tableRowInstance":null,"branchName":null,"eventType":"ScreeningVisit","formRepeatNumber":3,
"value":"2022-03-09T06:00:00.000Z","cycleNumber":null,"empty":false,"treatmentArm":null}]
Parent topic: Control the behavior of a rule