š¢ Set the default value of a number field.
1. Overview
This Interaction is designed to set the default value of a number field in a subrecord to 1.
2. Example
In the below example, the function checks if the quantity field within the "general-consultants-order-items" subrecord is empty or null, and if so, it sets it to a default value of 1.
async function handler(clev) {
let actions = [];
let updatedSubrecords = clev.event.payload.indices.map((index) => {
let currentQuantity = clev.getSubValueBasedOnIndex(
"general-consultants-order-items",
index
).quantity;
let isCurrentQuantityEmpty =
currentQuantity === "" || currentQuantity === null;
actions.push(
clev.updateSubValueBasedOnIndex(
"general-consultants-order-items",
index,
{
quantity: isCurrentQuantityEmpty ? 1 : currentQuantity,
}
)
);
});
return clev.mergeAll(actions);
}š Need Help?
