How to filter Sales Order line items where the "On...
# ask-stanley-ai
v
How to filter Sales Order line items where the "On Hand Quantity" is greater than or equal to the remaining quantity in SuiteScript when creating a search?
c
AI generated answer (using internal Slack threads):
To filter Sales Order line items where the "On Hand Quantity" is greater than or equal to the remaining quantity in SuiteScript when creating a search, you can use the
N/search
or
N/query
modules in SuiteScript. Here is a general strategy: 1. Create a Transaction Saved Search in the NetSuite UI with the following criteria: - Main Line is False - Shipping Line is False - Tax Line is False - Type is Sales Order - Status is Sales Order: Pending Fulfillment, Partially Fulfilled, Partially Fulfilled/Pending Billing - Quantity Available is greater than 0 - Formula (Numeric) case when
{quantity}-{quantityfulfilled}
!= 0 then 1 else 0 end (then make the value = to 1) 2. In the Results tab, include the following columns: - Document Number - Name - Item - Quantity Available - Quantity Fulfilled 3. Save the search and note down the internal ID. 4. In your SuiteScript, use the
N/search
module to load and run the saved search. Here is a sample code snippet:
Copy code
javascript
var mySearch = search.load({
   id: 'customsearch_my_saved_search' // replace with your saved search internal ID
});

mySearch.run().each(function(result) {
   // process each result
   return true; // continue to next result
});
Remember, the Quantity Available field is not directly available on the Sales Order record. It is a field on the Item record. Therefore, you need to join to the Item record to get this field. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84353894
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830554783
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829311311
Please provide your feedback on this answer.