Skip to main content
Solved

Button to copy data from1 field to another

  • January 15, 2022
  • 3 replies
  • 51 views

Forum|alt.badge.img+3

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

Best answer by kuovonne

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

3 replies

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • Answer
  • January 15, 2022

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


Forum|alt.badge.img+3
  • Author
  • New Participant
  • 2 replies
  • January 15, 2022

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

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • 6009 replies
  • January 15, 2022

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.