Button to copy data from1 field to another

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

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');
}

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.

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.