There are two problems with that. The major problem is it would run every time you opened the sheet, so it would keep overwriting new values with old values. The other problem is you can't create new repeating sections that way. You need a function to create new rows. To solve the first problem, create a hidden attribute: <input type="hidden" name="attr_codeversion" value="0" /> Then you need to create two functions. First the following sheet worker: on('sheet:opened', function () { getAttrs(['codeversion'], function (values) { if ((parseFloat(values.codeversion) || 0) < 1) { updateWounds(); } }); }); What this function does: very time the sheet is opened, it checks the codeversion attribute. If it is 1 or higher, it does nothing. If it is less than 1, it launches a function to convert the wound boxes to a repeating section. that function will also set the codeversion attribute to a value of 1. So after the update function has run once, it will never run again. The update function is below. What it does: it builds an array of all the wound attributes, from 1-10, and gets their values. Then it loops through 1 to 10, and checks in order, the wound1, wound2, etc attribute. If there is a value, it creates a new rowid for the section id, and creates new attribute names for the wound, wound_days, and wound_notes within that section, and grabs the corresponding values from the old stats. Then it sets code_version to 1 and updates the sheet. function updateWounds() { const fieldnames = []; const rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; rows.forEach(num => fieldnames.push(`wound${num}`, `wound${num}_days`, `wound${num}_notes`)); getAttrs(fieldnames, function (values) { const output = {}; const getValue = field => (values[field] != 'undefined') ? values[field] : ''; rows.forEach(row => { const wound = parseInt(values[`wound${row}`]) || 0; if (wound > 0) { const rowid = generateRowID(); output[`repeating_wounds_${rowid}_wound`] = wound; output[`repeating_wounds_${rowid}_wound_days`] = getValue(`wound${row}_days`); output[`repeating_wounds_${rowid}_wound_notes`] = getValue(`wound${row}_notes`); } });
output.codeversion = 1;
setAttrs(output); }); } If your old attributes dont have a wound1_notes section, you just need to make two changes: Change this line rows.forEach(num => fieldnames.push(`wound${num}`, `wound${num}_days`, `wound${num}_notes`)); to rows.forEach(num => fieldnames.push(`wound${num}`, `wound${num}_days`)); and delete this line: output[`repeating_wounds_${rowid}_wound_notes`] = getValue(`wound${row}_notes`);