Help

Automation : copy a field value into another field

6459 8
cancel
Showing results for 
Search instead for 
Did you mean: 
Production2
4 - Data Explorer
4 - Data Explorer

Hello to all,

I would like to be able to copy every day at a precise time the data contained in a column and paste it in another column.
This is to compare the progress each day with the day before.

Would you have an idea?
I was going to use an automation but I can’t find the solution.

Thanks a lot,

A.

8 Replies 8

Hi @Production2

Hmm, I’m thinking you could either:

  1. Set up a formula field that you use as your automation trigger and then make its action to paste the value into the other column
    • This would burn through automations really quickly depending on how many records you have, as it would need to run once per record
  2. Make an automation to run at a scheduled time every day and write a script to do what you need
    • You’d need a Pro account for this
Production2
4 - Data Explorer
4 - Data Explorer

Hi @Adam_TheTimeSavingCo ,

Thank you for your answer :winking_face:

I’ve got a Pro Account but I don’t know how to write this script to make your second proposal.

Hey @Production2,

If you’ve got the time and automations to burn through, I’d really advise going with the first option if you’re not familiar with scripting. That way you can make changes and stuff without relying on anyone else

If you’re really set on going down the scripting road, DM me a link to your base as well as the name of the column you want copied and the column to copy into and I’ll see what I can do

You can link the table to new ‘copier’ 1-record table linked to all records, set lookups or rollups and copy to other field (or 7 fields for week/30 fro month) with no code, pure automation

or use that template to copy all column. Set 3 values.

const table=base.getTable(' Set table name ');
const [SRC,DEST]=[' Set_source_field ,' Set_destination_field '];
const upd=await table.selectRecordsAsync({fields:[SRC]}).then(q=>
q.records.map(r=>({'id':r.id,'fields':{[DEST]:r.getCellValue(SRC)}})))
while(upd.length) await table.updateRecordsAsync(upd.splice(0,50))

note that it copy text to text.
if your Source fieldtype is multi/single-select, lookup or something ‘more complex’, you need to change [DEST]:r.getCellValue(SRC) to
.getCellValueasString(SRC) - to read ‘complex value’ as usual string

in worst case, when you need to write to ‘complex field’, you need additional converting

Hello @Alexey_Gusev,
Thank you for this answer.
Indeed it is about copying a lookup field with a duration.
(I want to know the duration progression between 2 days)

When I try your template I’ve got this error message :
ERROR
Syntax error: Unexpected identifier [script.js:2:25]

const table=base.getTable(’ Set table name ‘);
const [SRC,DEST]=[’ Set_source_field ,’ Set_destination_field '];
const upd=await table.selectRecordsAsync({fields:[SRC]}).then(q=>
q.records.map(r=>({‘id’:r.id,‘fields’:{[DEST]:r.getCellValueasString(SRC)}})))
while(upd.length) await table.updateRecordsAsync(upd.splice(0,50))

Sorry for my cognitive bias, I expect it to be obvious and told it, as if I explain to another coder. Also, my English is far from perfect.
You should set 3 values: your table name and field names here, like this:

image

Also, use getCellValueasString(SRC) to read Lookup field as string
destination field should be writable (not Lookup), and preferably SingleText or LongText.

Production2
4 - Data Explorer
4 - Data Explorer

Hello,

Thank you very much for your answer.
After several tests the script works but only between two single text fields :frowning:
Despite trying to modify the script with getCellValueasString(SRC) I still have an error

TypeError: r.getCellValueasString is not a function
at on line 3
at on line 3
at async main on line 3

For info my source is a Duration Rollup with condition field and my destination is a Duration field

paulo
6 - Interface Innovator
6 - Interface Innovator

You can also use a no-code alternative for this use case by utilizing a third party that integrates with Airtable. We have created an extension that will allow you to automatically copy values from one field to another.