JQL事件属性筛选查询报错:ReferenceError: type is not defined
Hey there! Let's break down what's going wrong with your query and get it working smoothly.
What's Causing the ReferenceError?
The core issue is how you're accessing the account-type property. In JavaScript (which JQL builds on), using dot notation like user.properties.account-type makes the engine interpret the hyphen as a subtraction operator. It thinks you're trying to subtract a variable named type from user.properties.account—and since type isn't defined anywhere, you get that error.
On top of that, your current filter logic has a contradiction: you're trying to find items where account-type is both "ecommerce" AND "free" at the same time, which will never return any results. You probably meant to filter for one or the other, or maybe target different properties in each check.
Corrected Query Examples
Here are two fixed versions depending on what you actually need:
Option 1: Filter for either "ecommerce" or "free" account types
function main() { return Events({ from_date: "2018-01-01", to_date: "2018-03-30" }) // Use bracket notation to safely access the hyphenated property .filter(function(event) { const accountType = event.properties["account-type"]; return accountType === "ecommerce" || accountType === "free"; }); }
Option 2: Filter for user account type = "ecommerce" AND event account type = "free"
If you intended to check two different properties (user vs. event), adjust it like this:
function main() { return Events({ from_date: "2018-01-01", to_date: "2018-03-30" }) .filter(function(event) { return event.user.properties["account-type"] === "ecommerce" && event.properties["account-type"] === "free"; }); }
Key Takeaways
- Hyphenated properties: Always use bracket notation (
["property-name"]) instead of dot notation when accessing properties with hyphens or special characters. - Logical consistency: Double-check filter conditions to avoid contradictory checks (like looking for two mutually exclusive values at once).
内容的提问来源于stack exchange,提问作者abdallahalhakim

