Can anyone point me in the right direction or give...
# suitescript
c
Can anyone point me in the right direction or give me a quick example of how I would run a search, then match a field from that search with a field in a subsequent search? I've basically written two searches, one is Backorders by Location and the other is Inbound Shipments by Location. I need to essentially join the two searches by Location to filter down the Inbound Shipments based on the Locations. i.e. if there's a backorder for an item at a location, call up a list of all Inbound Shipments for that inventory item on the manifest and total the estimated quantity of all of the inbound shipments for that location.
d
Could be done with two searches, but seems a prime use case for SQL/`N/query` module
I'm not one to ask about writing said SQL query, however For the search approach, my instinct would be to run the first search, get an array of applicable item ids (those with a backorder for the specific location), then use that as a filter of the next search (inbound shipment). Filter would be similar to
{'item', 'anyof', ...[_arrayofitemids_]}
❤️ 1
👍 1
j
Thanks @David B I haven't yet try that concept. Cause in my end I tried using 2 search to identify the item
c
Any example of how I would implement the
{'item', 'anyof', ...[_arrayofitemids_]}
part of it? I think that might also be the right approach though how would I put this into an array to search? Would you split each result row into separate fields, extract the
locationId
to match the item record against the
receivinglocation
of the
inboundshipment
the use the rest of the information after the matching is done?
d
ah, I did not realise you were search multiple locations at once. So you'd have to match where item and location were the same. You still could do it, but it's another vote in favour of SQL. For someone a little more versed in it than me, that SQL would be a cinch
c
The multiple locations isn't really a problem as it simply becomes another filter, though getting the syntax itself of how to essentially string two saved searches together where I run one, get the result of the first then use those results as the basis for a subsequent search (like you visualised in your [arrayofitemids] example) is exactly what I need. When I search for anything in Google it just returns irrelevant answers as it only gives basic scenario examples. If you happen to see any examples of linking two saved searches and use of the arrayof from previous saved searches please clue me in and thanks for the point in the right direction!
d
sure thing, hard to elaborate more without actually just writing the script
👍 1
So... I asked chatGPT about that query, and even I know that this won't work, but it's the right idea if you decided to use
N/query
Assuming that the table names are
sales_orders
and
inbound_shipments
and they have columns named
location
,
item
,
quantity
, and
order_number
, the PL/SQL query for NetSuite that joins the two tables and matches the location and item on each table can be written as:
c
Ok thankyou, gives me an idea anyway!
ChatGPT is pretty cool
You might want to have a look at this Chrome Extension. It combines and compares Google with ChatGPT search results: https://chrome.google.com/webstore/detail/chatgpt-for-google/jgjaeacdkonaoafenlfkkkmbaopkbilf/
👀 1
This is what ChatGPT came up with when I queried it about nested saved searches:
Copy code
// Define the inner saved search (nested search)
var nestedSearch = search.create({
    type: 'customer',
    filters: [['internalid', 'anyof', '123', '456']],
    columns: ['internalid', 'companyname']
});

// Define the outer saved search
var outerSearch = search.create({
    type: 'invoice',
    filters: [['mainline', 'is', 'T']],
    columns: ['internalid', 'tranid']
});

// Add the nested search as a subquery in the outer search
var sublist = outerSearch.createSublist({
    name: 'customers',
    join: 'customer',
    search: nestedSearch
});

// Add columns from the nested search to the outer search
sublist.addColumn({
    name: 'internalid',
    join: 'customer'
});

sublist.addColumn({
    name: 'companyname',
    join: 'customer'
});

// Run the search
var searchResults = outerSearch.run();
To create a nested saved search using search in NetSuite SuiteScript, you can follow these steps: 1. Define the inner saved search using the
search.create()
method, just as you would for any other saved search. This saved search will be the nested search that will be used as a subquery in the outer search. 2. Define the outer saved search using the
search.create()
method. You can use the
search.createFilter()
method to add filters to the outer search. 3. Use the
search.createColumn()
method to add any columns that you want to retrieve from the outer search. You can also use the
search.addColumn()
method to add columns from the nested search that you want to retrieve. 4. Add the nested search as a subquery in the outer search by using the
search.createSublist()
method. This method takes the nested search as its parameter and adds it as a sublist to the outer search. Example was the code above
d
the scary thing isn't that it's wrong, it's how confidently/deceptive the wrongness is It's just inventing API that don't even exist, wtf
yeah, I rest my case with that step-by-step it's provided. Oof
c
LOL. That's the problem with old "confidence over competence", isn't it? They need to program a CRAP test into it so it doesn't just "sound true", it has actually peer-reviewed answers to "prove" that it's as right as it can be. Show actual examples, not just piece stuff together that it finds to make it believable!
d
it's crowd sourced intelligence, that's why I made sure to take the time to tell it off for using reserved words incorrectly
c
The only issue with that is that too bad if the crowd is wrong! i.e. the world is flat, all of the documentation says so! 🙂 Galileo would be laughing his head off, with "Do you want the right answer, or the readily accepted one?"