Help

Button to copy data from1 field to another

Topic Labels: Scripting extentions
Solved
Jump to Solution
2494 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Alastair_Noon
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi,

I’m learning how to use the scripting block, not too successfully. I have tried to adapt the scripting block “select a record” and one from the thread about linked fields from @capt & @JonathanBowen but I can’t seem to get it to work. I am trying to copy the text output by a formula field (EQ3) into the text field Notes using a button.

Any help or advice would be much appreciated!

Many thanks,

Alastair
Screenshot 2022-01-15 at 11.11.17

This is what I have so far:

// Name of table
let table = base.getTable("Requisitions");

// This script is run from a button field & will use the button's record
let record = await input.recordAsync('Select a record to use', table);

if (record) {
    // You can use record.getCellValue("Field name") to access
   let oldValue = record.getCellValue("EQ3");
   
   let newValue = oldValue;
   output.text(newValue);

    table.updateRecordAsync(record,{"Notes": newValue});
} else {
    output.text('No record was selected');
}
1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

Welcome to the Airtable community!

Are you getting any error messages? Does the script run at all?

What is the result of the output.text(newValue)?

Try converting getCellValue to getCellValueAsString

Also try adding the await keyword in front of table.updateRecordAsync

See Solution in Thread

3 Replies 3
kuovonne
18 - Pluto
18 - Pluto

Welcome to the Airtable community!

Are you getting any error messages? Does the script run at all?

What is the result of the output.text(newValue)?

Try converting getCellValue to getCellValueAsString

Also try adding the await keyword in front of table.updateRecordAsync

Thank you!

By adding both of these things in the script now works runs properly - thank you!

The button still currently applies to all records regardless of whether or not EQ3 is populated, do you know how it is possible to change this?

This is my code, with your revisions @kuovonne

// Change this name to use a different table
let table = base.getTable("Requisitions");

// This script is run from a button field &will use the button's record
let record = await input.recordAsync('Select a record to use', table);

if (record) {
    // You can use record.getCellValue("Field name") to access
   let oldValue = record.getCellValueAsString("EQ3");
   
   let newValue = oldValue;
   output.text(newValue);

   await table.updateRecordAsync(record,{"Notes": newValue});
} else {
    output.text('No record was selected');
}

No, it is not currently possible to change this. You can write your script to detect whether the field is empty and product different output when it is.