Accessing Vendor Payment Apply records from Transaction table via SuiteQL in Netsuite - netsuite

I wanted to access Vendor Payment Apply records on the Vendor Bill Payment Record. The challenge I'm facing here is that Vendor Payment record is of type Transaction, so we can put a where condition to filter out those records, but I'm not able to figure out how to get the Vendor Payment Apply records. Basically here's something I want to achieve, something on the lines of this query:
select * from transaction as t
join
VendorPaymentApply as vpa on t.refNum = vpa.refNum // need to find a way to access this table
where
t.type = 'vendorPayment'
and t.date BETWEEN (x, y)

Related

NetSuite formula to show quantity ordred on first order

We have a saved search in place that displays date of first order and last order by customer & item within a given date range. For example - Looking at sales for May 2022 - today, it shows the item, the customer, the date they first ordered the item, and the date they last ordered the item.
I am now also trying to incorporate the quantity ordered on the first order.
crietera
results
I've tried the following, but keep getting an invalid expression. Can anyone advise on how I might be able to display the qty on the date of the first order?
MIN(CASE WHEN {custbody_reporting_ship_date} THEN {quantity} END)
and
CASE WHEN (MIN({custbody_reporting_ship_date})THEN {quantity} END)
I think this can't be achieved in saved search via simple formula. You may want to try below, what I will do is try to record the first and last order id in the customer record, then from customer saved search you can source from these order fields to the order details.
Create 2 custom entity fields applied to customer
first order id => Type:List/Record => List/Record:Transaction
last order id => Type:List/Record => List/Record:Transaction
Create 1 saved search to get the first order id per customer
Similar to the one that you created, the result field just need the customer internal id and min(document number) and filter need to add customer.internal id
Create 1 saved search to get the last order id per customer
Similar to the one that you created, the result field just need the customer internal id and max(document number) and filter need to add customer.internal id
Create 2 scheduled workflows, to update the first order id and last order id fields in respective customer record.
Create your first and last order customer Saved Searches using the 2 custom fields to source for the order details.
Not sure if this help.

issue with the usage of BELONGSTOMANY or HASMANY on sequelize

I've been using NODE.JS - SEQUELIZE to deal with POSTGRES database. But, it's been a while that I am facing an issue.
I have two TABLES:
FIRST TABLE: Purchases. Inside of this table, there is a column which keeps the foreign key of the Products table, because they are associated. But, as long as I'veen been coding, I realized that I needed to "insert" more than one products at once, like an array, for those people who will buy more than one product at once.
SECOND TABLE: Products.
I want something like this => Allow to a purchase inside of Purchases to have more than one products associated with. But all that I can do is make the product foreign key column in purchases table accepts only intenger (ID) of only one product.
For exemple:
The user X buyed multiple products, so then in product in Purchases will have the products [1,3,5] and these numbers are the product's ID that I would like to associate with the Products table.
print of the PURCHASES MODEL: purchases MODEL(not the migration) on sequelize
print of the PURCHASES TABLE: purchases table structure
print of the PRODUCTS TABLE: products table structure
The conclusion I've have reached was using "Belongs to MANY" or "Has many", but I don't how.
Thanks.
I propose you to add another table to achieve multiple products in one order:
ORDER table - stores one record per a customer order (all columns that related with an order as a whole)
ORDER_ITEMS - stores items inside each order (columns: a link to ORDER, a link to PRODUCT, a quantity, a price and other related columns (a discount and so on)
PRODUCT - stores a catalog of products to buy

NetSuite Saved Search Showing Inside Sales Rep If There Is One

I'm trying to do a saved search in NetSuite that returns all of the customers in a particular state and, for those which have an Inside Sales Rep, the name of that rep.
But if I specify Sales Team Role = Inside Sales Rep in the criteria, the result only contains customers who have an Inside Sales Rep (and we have some that do not).
If I don't specify the Sales Team Role in the criteria but list Sales Team Role and Sales Team Member in the Results, then I get every customer, but a row for every sales team member, with their role - so multiple lines per customer. I don't want that.
I just want a line in the results for each customer and, if there is an Inside Sales Rep on that customer, that person's name.
Any suggestions?
Basically, you need a left join ;).
Instead, you can use a formula to return either the sales rep if the role is inside sales, or null, or null if there is no sales rep. Then you aggregate it using maximum.
Or you can use the rank function (using the formula above within the rank syntax), selecting where rank = 1. This allows you to save your aggregation for when you need it, at the expense of clarity.

Duplicate results in NetSuite Contact search

Can someone help me understand why I get duplicate results on a Contact search in NetSuite only when I include a Customer field as a result column? Below are steps for how I am reproducing this problem.
Create a new Contact search
Add a single criterion: Internal ID is any of 230, 597, 1808
For results, return just a single column, Internal ID
Submit the search. 3 results are returned as expected (screenshot below).
Return to the criteria for the search
For results, add a second column, Customer : Internal ID
Submit the search again. This time six (6) results are returned (screenshot below).
What is incredible to me is not only are there double the number of results, but the results actually appear to be unique based on the fact that the Customer : Internal ID values are different. What causes this behavior?
It depends upon the field you give as result. If you many number of field in the result section, each result field that match your search criteria or filter will be shown irrespective of what is already displayed(ie,duplicates will be shown).
Use criteria to filter it out or reduce the result field
This is a similar interaction to the "main line" criteria on a transaction search. a contact is a record in itself. When searching for a contact it returns a singular one. As soon as you tell it to return an internal ID of a related document or customer you will find that sometimes a contact can exist in two places at once. So your second set of results basically says that (for example) Contact 597 is connected to customer 168 and customer 167. Contact records are not the same as a customer record.
Each contact has its own internal id, however, the same contact might show up to different records because NetSuite allows you to attach a contact to more than one customers/sub-customers. Therefore when you add customer: internal id it's pulling out all the customers that have the same contact on their records. You can add another column that shows the customer name/id under results and see if this is what happened.

Viewing all Products that a Customer has purchased on Stripe

How can I view all Products that a Customer has purchased using the Stripe API? Is there a specific event that is sent out when a purchase occurs? I'm seeing that there is an Orders item as well, but am not sure that Products can only be purchased as part of Orders.
Sample query for getting all Orders by a Customer:
from stripe import Order
Order.list(customer=customer_1['data'][0].id)
Basically I want to get all non-subscription-based items that the user has purchased -- will querying the API for Orders this way give me all non-subscription-based items, since a Product must necessarily each be tied to an Order, or is there a different/better way of doing this?
You can retrieve all orders for a customer with the list all orders method and the customer parameter.
You can then go through the order's items attribute to find the SKUs included in the order.
Finally, you can use a SKU's product attribute to retrieve the product associated to the SKU.
In Python, you could do something like this:
customer_id = "cus_..."
products = [] # list of products ordered at least once by the customer
orders = stripe.Order.list(customer=customer_id)
for order in orders.auto_paging_iter():
for item in order.items.auto_paging_iter():
if item.type == "sku":
sku = stripe.SKU.retrieve(item.parent)
if sku.product not in products:
products.append(product)
The above code is not very efficient as it would send a SKU retrieve request for every item of type "sku". In practice, you'd likely want to cache the results and only retrieve each SKU once.

Resources