Introduction
I really enjoy using Zapier, though I am not a formally trained developer; I possess basic skills in a few programming languages.
Issue Details
I'm encountering a challenge in the "code by zapier (JavaScript)" section. I have a simple script that modifies a date format provided by a Woocommerce event through a plugin:
let rawData = input.OrderDate; let position = rawData.indexOf(",");if (position > 0) {
let formattedDate = rawData.substring(position + 1); // => 00-00-0000
formattedDate = formattedDate.substring(0, 11); // => 00-00-0000;
} else {
let formattedDate = rawData.substring(0, 10); // => 00-00-0000;
}
output = [{dateOfFirstLesson: formattedDate}];
However, in some instances, OrderDate is not defined, which leads to the following error message:
Error: TypeError: Cannot read property 'indexOf' of undefined in theFunction (at eval (line 52, column 23), at line 13, column 12) and eval (at line 52, column 23, at line 34, column 20) in Domain.
Questions
Is my reasoning accurate? Should I verify if the variable is defined before executing the script? What is the correct way to accomplish this?
I appreciate your help in advance!