findOrdersByNumber
Introduction
The findOrdersByNumber
function allows locating a specific order by its order number. When executed in the Execute JavaScript block, it checks for the existence of the order based on the order number provided by the customer and, if found, returns as a response an array with complete details about the order in question.
How to Use
-
First, it is necessary to use the advanced settings of our WhatsApp messages to request the order number from the customer, saving the response provided by the customer into a variable, which in this case will be
payload.number
.
Note: To learn more about the advanced settings of our WhatsApp messages, visit our help center article: Help Center – Understanding the Logic, Time, Chat, and Advanced Actions in Automations
-
Next, as soon as the customer provides the order number, within the automation structure, we will use the Execute JavaScript block to run the
findOrdersByNumber
function and search for the order associated with the provided order number. -
In the Execute JavaScript block, we use the code
payload.orders = await findOrdersByNumber(payload.number)
to search for the order associated with the number provided by the customer. In this way, the order number saved in thepayload.number
variable is used by thefindOrdersByNumber
function to retrieve the order linked to that number. The result is stored inpayload.orders
as an array containing the corresponding order.
-
The search response may return, in the following messages, information about the order found.
Example Code
Example Code
Note: In the example code, if no orders are found for the provided phone number, the message “No orders found” will be displayed.
To structure the response message containing the order data in this example, we use the Reportana® Script template language, which supports for
and if/else
structures. These commands allow for detailed and conditional formatting of the displayed information. To deepen your understanding of Reportana® Script and explore additional examples, refer to the full documentation: Reportana® Script - Documentation.
Return of the findOrdersByNumber
Function
Response Data
The search returns various detailed information about the orders, including:
- Customer Data: Name, phone number, email used to place the order, etc;
- Order Information: Order ID, payment status (e.g., paid, pending), payment method (e.g., boleto, credit card), order creation date, etc;
- Address Data: Billing and shipping address, including city, state, ZIP code, etc;
- Order Items: Product name, variant (e.g., color), quantity, unit price, product image URL, etc;
- Payment Information: Boleto URL, boleto digitable line, due date, Pix copy and paste code, total order value, etc;
- Useful URLs: Tracking link and any other relevant URLs.
This data enables composing personalized messages to inform the customer about the details of the orders associated with the phone number used in the search.