Apr 08, 2023 06:54 PM
I'm going to try and over-simplify what I'm trying to do. Here's the current set-up of my table.
- I have three rows, Apple Picking, Pear Picking, Cherry Picking. For each row I have the following fields, Blank Start Date, Blank End Date, Apple Picking Start Date, Apple Picking End date, Pear Picking Start Date, Pear Picking End Date, Cherry Picking Start Date, Cherry Picking End date. See screenshot below "Before Script" for example of how this looks like in AT at the moment and the values in each field.
- I would like to run a script that would populate the Blank Start Date and Blank End Date with the appropriate values. For example, for Apple Picking, I'd like the script to pick-up the Apple Picking Start Date and populate it in the Blank Start Date field. See screenshot below "After Script" for example of how this looks like in AT at the moment and the values in each field.
If there's a formula I can use to do this, happy to do that do just wasn't sure if it was possible with a basic formula.
Apr 09, 2023 08:17 AM
Hi,
Formula might be enough, but it depends on data in table. Does 'NA' means literally 'NA' or 'N/A' or any other repeated value that is not date? You can, for example, concatenate all start fields and substitute 'NA' with empty string.
Otherwise, if you need strong relationship between value in noname field (I will call it 'After Script') and field name, you can use SWITCH
SWITCH({After Script},
'Apple Picking', {Apple Picking Start Date},
'Cherry Picking', {Cherry Picking Start Date},
....
'Pear Picking', {Pear Picking Start Date},
'' )
The last empty string value is default when {After Script} not match any of values above
Apr 09, 2023 08:22 AM
btw, you can use this little script to craft your formula, and maybe as scripting example
Just change 'TabName', 'Start date' and 'After script' according to your values
const myfields=base.getTable('TabName').fields.map(f=>f.name).filter(f=>f.includes('Start date'))
const middlePart=myfields.map(f=>`'${f.replace('Start date','')}',{${f}},`).join('\n')
output.text(`SWITCH({After Script},\n${middlePart}\n'')`)