I'm trying to add a filter for `Entity.type != 'Em...
# suiteql
b
I'm trying to add a filter for 
Entity.type != 'Employee'
, but it seems to ignore my filter. When I put Entity.type as a column, it returns "Employee", but when I apply the LOWER function to Entity.type, it returns "relationship field". This makes me think that when I try to do my filter
Entity.type != 'Employee'
, it's not working because
Entity.type
is actually returning "Relationship Field". How can I filter using
Entity.type
properly?
c
SuiteQL can get finicky around select/relationship fields, especially when they're multi-select fields. In this case, I don't think type is or should be multi-select, but apparently at least the person responsible for documenting the Analytics browser thinks it is... Anyway, if you can't find a mapping table or a table that contains the values for the type column (I looked and can't), you can always try something like
Copy code
SELECT
  COUNT(id)
FROM entity
WHERE REGEXP_INSTR(LOWER(BUILTIN.DF(type)), 'employee') = 0
or
Copy code
SELECT
  COUNT(id)
FROM entity
WHERE id NOT IN (
  SELECT id
  FROM employee
)
The second one works because some SuiteQL tables like
employee
appear to be filtered views (or something like that) on the entity table, where the IDs in the employee table refer to the same entries in the entity table
b
Wow so weird. That second one works like a charm. I didn't bother to try the first one because the second one makes the most sense to me.
c
Great, glad it works!
b
Thank you for your help!
m
This works for me
Copy code
SELECT BUILTIN.DF(entity.type),
FROM message
JOIN entity ON message.author = entity.id
WHERE BUILTIN.DF(entity.type) != 'Employee'
b
What does BUILTIN.DF do?
m
It's the equivalent of Result.getText on saved search, basically a helper function to join to the entity type table and get the textual value
In this case, it looks like entity.type is actually a join to another undocumented table
message has been deleted
FWIW creating the query in anayltics UI and exporting the SQL comes up with this undocumented BUILTIN
BUILTIN.MNFILTER(entity."TYPE", 'MN_EXCLUDE', '', 'FALSE', 'Employee')
which throws an error when I tried to use in SuiteQL
😂 3
netsuite 3
219 Views