HI Team, I'm new to SuiteQL: I want to run a searc...
# suiteql
r
HI Team, I'm new to SuiteQL: I want to run a search where it returns all the Children of a Assembly Item and also check the effective date and obsolete date to make sure its valid. • In this example Grand child 3 should be excluded • while Grand child 1 is part of the "Tree" via parent 2 • I have tried to do this via Normal search but it does not filter out Obsolete children and effect date of the children • Open to Ideas
@tdietrich Any thoughts 🙂
MY base search
a
I did end up doing this for a client. It's not perfect, but works for them as they have a fixed number of levels. It essentially makes use of UNION ALL to get the levels. So first query is Level 1, then UNION ALL to the children (query 2), UNION ALL to grandchildren (query 3), and so on and so on until you have the max number of levels you may have
select d.top_item, d.top_item_id, d.bom_level, d.item, d.parent,d.item_id,d.quantity, BUILTIN.DF(i.location) as location, il.leadTime, il.atpLeadTime from ( select BUILTIN.DF(m.parentItem) as top_item,m.parentitem as top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '1' as bom_level from itemMember m where m.parentitem = 63542 and (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null) UNION ALL select b.top_item, b.top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '2' as bom_level from itemMember m INNER JOIN (select BUILTIN.DF(m.parentItem) as top_item, m.parentItem as top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '1' as bom_level from itemMember m where m.parentitem = 63542 and (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null)) b on m.parentItem = b.item_id where (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null) UNION ALL select c.top_item, c.top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '3' as bom_level from itemMember m INNER JOIN (select b.top_item, b.top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '2' as bom_level from itemMember m INNER JOIN (select BUILTIN.DF(m.parentItem) as top_item, m.parentItem as top_item_id, BUILTIN.DF(m.parentItem) as parent,BUILTIN.DF(m.item) as item, m.item as item_id, m.quantity, '1' as bom_level from itemMember m where m.parentitem = 63542 and (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null)) b on m.parentItem = b.item_id where (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null)) c on m.parentItem = c.item_id where (CURRENT_DATE < m.obsoleteDate OR m.obsoleteDate is null) ) d INNER JOIN item i on d.item_id = i.id INNER JOIN aggregateItemLocation il on il.item = i.id AND il.location = i.location
(pardon the formatting)
r
Woah
a
ends up producing a result like:
r
@Anthony (NimbusLabs) where do you find these fields top_item
sorry as I new to SuiteQL. been a safe search guy for the whole NS career
a
if you're familiar with SQL, these are just aliases (or custom label from a saved search)
The itemMember table is table with the majority of the data, then it's just joining to get the next level up
(or down)
r
Haven't had to play around since I started NetSuite about 8yrs ago.