fix(W2): graceful skip when customer link not yet filled (no crash)
When CP record is drafted with product set before customer, the webhook fires with customerId=null -> now returns skipWriteBack=true (routed to No-op) instead of throwing. Record re-fires webhook properly once customer field is set.
This commit is contained in:
+5
-1
@@ -38,7 +38,11 @@ const custProdId = $json.customerProductId;
|
||||
// 1. re-fetch the CP record
|
||||
const cp = await ncGet(`/api/v2/tables/${T_CUSTPROD}/records/${custProdId}`);
|
||||
const customerId = linkId(cp.customer);
|
||||
if (!customerId) throw new Error('CP has no customer link');
|
||||
if (!customerId) {
|
||||
// Gracefully skip when customer link not yet filled (CP record is being drafted).
|
||||
// The webhook will re-fire when customer is set later.
|
||||
return { json: { skipWriteBack: true, customerProductId: custProdId, reason: 'no customer link yet' } };
|
||||
}
|
||||
|
||||
// 2. load all active CPs for this customer
|
||||
const cps = await ncGet(`/api/v2/tables/${T_CUSTPROD}/records?where=(customer,eq,${customerId})&limit=1000`);
|
||||
|
||||
Reference in New Issue
Block a user