Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Scripting

927 2
cancel
Showing results for 
Search instead for 
Did you mean: 
jhincuy
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi

I'm trying to create a script for a ticketing machine. However, it looks like this (See screenshot below)

jhincuy_0-1717047359700.png

Here's the script that I used:

 

// Define the orders table
let ordersTable = base.getTable("Orders");

// Fetch all order records
let ordersQuery = await ordersTable.selectRecordsAsync({
    fields: ["Order Number", "Customer ID", "Name", "Email", "Phone Number", "Address", "Selected Meals", "Order Date", "Delivery Date", "Order Type", "Order Status"]
});

// Loop through each order and generate the ticket
for (let orderRecord of ordersQuery.records) {
    // Fetch order details
    let orderNumber = orderRecord.getCellValue("Order Number");
    let customerId = orderRecord.getCellValue("Customer ID");
    let customerName = orderRecord.getCellValue("Name");
    let customerEmail = orderRecord.getCellValue("Email");
    let customerPhoneNumber = orderRecord.getCellValue("Phone Number");
    let customerAddress = orderRecord.getCellValue("Address");
    let selectedMeals = orderRecord.getCellValue("Selected Meals");
    let orderDate = orderRecord.getCellValue("Order Date");
    let deliveryDate = orderRecord.getCellValue("Delivery Date");
    let orderType = orderRecord.getCellValue("Order Type");
    let orderStatus = orderRecord.getCellValue("Order Status");

    // Format the ticket content
    let ticketContent = `
        **Order Number:** ${orderNumber}
        **Customer Name:** ${customerName}
        **Email:** ${customerEmail}
        **Phone Number:** ${customerPhoneNumber}
        **Address:** ${customerAddress}
        **Selected Meals:** 
        **Order Date:** ${orderDate}
        **Delivery Date:** ${deliveryDate}
        **Order Type:** ${orderType}
        **Order Status:** ${orderStatus}
    `;

    // Output the ticket content
    output.markdown(ticketContent);
}
 
I want this ticket machine to look like an order receipt for online food ordering business. Thank you!
2 Replies 2

Could you provide an example of what you'd like it to look like instead?

To solve the '[object]' issue, try using `getCellValueAsString`.  Can't guarantee that'll work as I don't know what kind of field that is though

jhincuy
5 - Automation Enthusiast
5 - Automation Enthusiast

I would like something like this, which can also be printed. However, I'll try to use getCellValueAsString in the script.

jhincuy_0-1717051806093.png