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

argument
Expression or variable value to get logged and displayed for debug.

Only strings and numbers are supported as arguments, which means variables of these types can be used. If you want to use an object as an argument you must use the stringify() method so it is passed as a string.

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 the logMsg() 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 Window
dt1 =
      [{"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}]