Help

API Updating Script in Automation

Topic Labels: API
703 0
cancel
Showing results for 
Search instead for 
Did you mean: 
EricWongMusic
6 - Interface Innovator
6 - Interface Innovator

Hi, everyone!

I need some hints to solve the scripting problem. I am not a programmer and only know easy html. Please let me explain what I am trying to do and see if you can help.

I have setup a sync of a table 禮儀選曲 from Base A to Base B, so both Bases has the same set of data in this table. I have created a VIEW for any records meeting the filtering criteria in both bases.

I have setup an automation to create a record in a table 選曲表 of Base B triggered when any record(s) appear in the VIEW. The data of the new records are from the table 禮儀選曲. The recordID of the original record is also stored in the new record. Until this point, everything work fine.

I need to update the original record with the recordID of the auto created record. Since the automation cannot update record in another base, I have to use an API request to do this. I am just don’t know how to write this script to make it work. Please see my script and attached screenshot. Thanks for anyone would like to help! It is a church database for the Sunday Mass.

Here is my script copied from the API Document:

function () => {
    RecordID: string,
    SourceRecordID: string,
};
let inputConfig = input.config();
console.log(`The value of RecordID is ${inputConfig.RecordID}`);
console.log(`The value of SourceRecordID is ${inputConfig.SourceRecordID}`);
var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('app5edyi2jMvQd3Yn');

base('禮儀選曲').update([
  {
    "id": "SourceRecordID()",
    "fields": {
      "資料庫選曲表 RecordID": "RecordID()"
    }
  }
], function(err, records) {
  if (err) {
    console.error(err);
    return;
  }
  records.forEach(function(record) {
    console.log(record.get('禮儀編目'));
  });
});

The variable RecordID is the auto created record, and SourceRecordID is the original record.

Here are the screenshot of my automation setup:
Screenshot 2

0 Replies 0