Early Exit (lam.exit)
When writing a workflow step program and you need to exit the workflow early because a pre-condition is not met, use the keyword lam.exit
in your return object.
Example: Using our order fulfillment workflow example from Getting Started, suppose we needed to check that incoming order is not for a digital service before proceeding to send data to fulfillment centre.
1
Send Orders to Fulfillment Centre
(data) => {
const inputOrder = data.input;
+ if (inputOrder.isDigital) {
+ return {
+ "lam.exit": true,
+ // payload to be returned
+ "data": {
+ "message": "Skipped. Digital service orders should not be sent to fulfillment centre.",
+ "order": inputOrder,
+ }
+ };
+ }
// Use Array.map to transform the items array
const transformedItems = inputOrder.items.map(item => ({
sku: item.product.sku,
name: item.product.name,
quantity: item.quantity,
price: parseFloat(item.price) // Convert price from string to number
}));
// Construct the final output object
const outputOrder = {
customer_name: inputOrder.customerName,
customer_email: inputOrder.customerEmail,
customer_phone: "+1234567890", // Placeholder as source data is missing
shipping_address: {
street: `${inputOrder.shippingAddressLine1 || ''} ${inputOrder.shippingAddressLine2 || ''}`.trim(),
city: inputOrder.shippingCity,
state: inputOrder.shippingState,
zip: inputOrder.shippingZipCode,
country: inputOrder.shippingCountry
},
items: transformedItems,
shipping_method: "standard" // Default value as source data is missing
};
return outputOrder;
}
Last updated
Was this helpful?