logMsg()
在调试时获取有关规则逻辑的特定信息。在 JavaScript 表达式中根据需要放置日志语句,以显示定义的变量和消息的值以显示规则的行为。
语法
logMsg(argument)
参数
返回值
调试时,将返回传递给 logMsg() helper 函数的参数并显示在日志窗口中。
使用提示
注意:
由于logMsg() 帮助程序函数仅在调试模式下运行,因此在发布规则之前无需删除调用。
示例 3-81:使用变量标签
在记录变量时使用标签以使输出更易于遵循。
logMsg("weight: "+weight); // logs the label and the variable value
日志窗口中的输出
weight: 160
示例 3-82 使用日志语句调试规则逻辑
将消息记录为标志,以显示驱动规则行为的逻辑。
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;}
日志窗口中的输出
weight: 160
NOT weight > 160
示例 3-83:使用 stringify() 方法传递对象
使用 stringify() 方法将对象解析为字符串,以便在日志语句中使用。
var val1 = getValues("dt1","tpt");
logMsg("dt1 = "+JSON.stringify(dt1));日志窗口中的输出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}]父主题:控制规则的行为