Including print statements in programmable decisions
It's best practice to include print()
statements in programmable decisions because they can help in debugging and understanding the flow of execution. These print()
statements let you view the programmable output on the Logs tab, up until the point the code throws an error. This makes it easier for you to check the programmable functions that are working as expected and identify specific segments of the code that are causing errors when you test the decision model variant.
The following image shows an example of adding three print()
statements for the guest's gender
, city
, and guestType
to test a programmable.
On the Test Canvas, on the Logs tab, you'll see the programmable test results, where the output for the guest's gender
, city
, and guestType
are printed.
For enhanced debugging, you can also print entire JavaScript objects using the print(JSON.stringify(example));
statement. This outputs the object in a readable, formatted JSON structure with line breaks and indentation.