Hi everyone,
I’m working on a pay-at-table app for restaurants and need some help with correctly updating list ofOrderItems
based on an API response. Here’s what I’ve done and the issue I’m facing:
Initial Setup: Creating OrderItems on Page Load
Creating OrderItems:
- Method: On page load, I use “Schedule an API Workflow on a List” to create order items.
- Backend Workflow: The workflow
createorderitem
loops through the list ofMenuItems
from the API response and creates each item individually in theOrderItem
database. - Database Structure: Each
OrderItem
is created as an individual entry, allowing eachOrderItem
to be displayed in its own row within a repeating group. - Result: This setup works well, with
OrderItems
correctly created and linked to a singleOrderSummary
.
Issue: Updating OrderItems Using “Do Every 30 Seconds” Workflow
Update Process:
- Method: In the “Do Every 30 Seconds” workflow, I attempt to update
OrderItems
using another backend workflow calledupdateorderitem
. - Problem: The workflow does not iterate over each
OrderItem
entry correctly. Instead, it evaluates the list as a whole in the “Schedule an API Workflow” action. - Current Limitation: Because of this, I’m forced to use the
:firstitem
operator, resulting in only the first item being updated instead of iterating through all items.
What I Want to Achieve
If the MenuItem
list changes in the API response I get in the “Do Every 30 Seconds” workflow, I want these changes to be reflected in my OrderItem
database. Specifically:
- Comparison: Check if any data has changed compared to the current
OrderItem
data. - Update: Update the
OrderItem
if changes are detected. - Addition/Deletion: Add new
OrderItems
if they are in the API response but not in the database, and deleteOrderItems
if they are no longer in the API response.
Required Solution
- Goal: I need a method to compare incoming data from the API with existing data in the
OrderItem
database. - Actions:
- Comparison: Check if any data has changed compared to the current
OrderItem
data. - Update: Update the
OrderItem
if changes are detected. - Addition/Deletion: Add new
OrderItems
if they are in the API response but not in the database, and deleteOrderItems
if they are no longer in the API response.
- Comparison: Check if any data has changed compared to the current
Has anyone dealt with a similar issue or can suggest a good solution for this? Thanks in advance for your help!
Example list from API response:
“menuItems”: [
{
“menuItemId”: 101,
“definitionSequence”: 1,
“name”: “Wine”,
“quantity”: 2,
“unitPrice”: 5.99,
“priceSequence”: 1,
“total”: 11.98,
“seat”: 1,
“referenceText”: “No onions”,
“surcharge”: 0.50,
“itemDiscounts”: [
{
“discountId”: 201,
“name”: “Discount”,
“seat”: 1,
“referenceText”: “Promo”,
“total”: 1.00,
“isAutomatic”: true
}
]
},
{
“menuItemId”: 102,
“definitionSequence”: 2,
“name”: “Steak”,
“quantity”: 1,
“unitPrice”: 4.99,
“priceSequence”: 1,
“total”: 4.99,
“seat”: 1,
“referenceText”: “No dressing”,
“surcharge”: 0.25,
“itemDiscounts”: [
{
“discountId”: 204,
“name”: “Discount”,
“seat”: 1,
“referenceText”: “Promo”,
“total”: 0.75,
“isAutomatic”: true
}
]
},
{
“menuItemId”: 103,
“definitionSequence”: 3,
“name”: “Salad”,
“quantity”: 1,
“unitPrice”: 14.99,
“priceSequence”: 1,
“total”: 14.99,
“seat”: 1,
“referenceText”: “Medium rare”,
“surcharge”: 0.50,