Hi @████████ I'm not entirely sure how you want to use those values, but I'll show you a way to place the value of each row of the % Miles Cost Distribution in a text field, so you can then use those text fields as independent values. (I'm not sure if that's your goal.).
Let's set up some implementations first:
1- Where you have the fields within the Collector, insert a new text field with the following variable: Mileage_Row_Count, and in the Advanced tab, enter the following formula: =COUNTIF(Collection_1.V__,"<>") : Replace the variable I put there: Collection_1.V__ with the variable that corresponds to your % Miles Cost Distribution field. Then hidden counter field updates its value automatically whenever a row is added or removed.
2- Put the follow JavaScript Code in your JS Section:
/* Sync % mileage values from collection (field 15) into
standalone fields 5, 6, 7 — including when rows are deleted
Replace the IDs numbers according your collection fields*/
(() => {
const COLLECTION_FIELD = 15; // column inside the Collection
const ROW_COUNT_FIELD = 16; // hidden counter field
const TARGET_FIELDS = [12, 13, 14]; // text fields outside the table
// Helper: flatten LF objects -> primitive
const simplify = raw =>
raw && typeof raw === "object"
? ("data" in raw ? raw.data
: "value" in raw ? raw.value
: "dateStr" in raw ? raw.dateStr
: "")
: (raw ?? "");
// Main sync routine
function syncMileageRows() {
let rawVals = LFForm.getFieldValues({ fieldId: COLLECTION_FIELD });
if (!Array.isArray(rawVals)) rawVals = [rawVals]; // homogenise
TARGET_FIELDS.forEach((fieldId, idx) => {
LFForm.setFieldValues({ fieldId }, simplify(rawVals[idx]));
});
}
// ---------- initial run ----------
syncMileageRows();
// ---------- react to edits ----------
LFForm.onFieldChange(syncMileageRows, { fieldId: COLLECTION_FIELD });
// ---------- react to row added / deleted ----------
let prevCount = LFForm.getFieldValues({ fieldId: ROW_COUNT_FIELD });
LFForm.onFieldChange(() => {
const newCount = LFForm.getFieldValues({ fieldId: ROW_COUNT_FIELD });
if (newCount !== prevCount) {
syncMileageRows(); // rows changed — resync
prevCount = newCount;
}
}, { fieldId: ROW_COUNT_FIELD });
})();
In the previous script, in my test case, replace ID 15 with the ID that corresponds to your % Miles Cost Distribution field.
Then, replace ID 16 with the ID that corresponds to the hidden Mileage_Row_Count field.
IDs 12, 13, and 14 correspond to the IDs of the text fields I used for this example. Replace them with the ones you use. * These fields must be outside the Collector. You can have them hidden (but saving the value while hidden) or read-only. It depends on how you want to do it.
The script also allows you to dynamically delete the values in those text fields if you delete any of the rows. This way, you only keep the values you actually use per row in the associated text fields.
Perhaps this can be done in other ways, but I'm leaving this one here just in case it helps. Let me know if it's what you needed.