Skip to content

Instantly share code, notes, and snippets.

@Przemocny
Created December 3, 2022 14:58
Show Gist options
  • Save Przemocny/f8a1a44c136897a83f93bc7738feb797 to your computer and use it in GitHub Desktop.
Save Przemocny/f8a1a44c136897a83f93bc7738feb797 to your computer and use it in GitHub Desktop.
airtable.mergeEntriesOnFormSubmit.js
async function init() {
const lessons = await getRecords('STUDENTS LESSONS')
const newItem = lessons.find(({ fields }) => {
const waitingForReaction = typeof fields['__HELPER_REF'] == 'string'
return waitingForReaction
})
if (!newItem) {
console.log('nothing found')
return;
}
const idToMatch = Number(newItem.fields['__HELPER_REF'])
const toUpdate = lessons.find(({ fields }) => {
return fields['ID'] == idToMatch
})
const fieldsToUpdate = {
'CO BYŁO ROBIONE': newItem.fields['CO BYŁO ROBIONE'],
'Z CZYM STUDENT MIAŁ NAJWIĘKSZE PROBLEMY': newItem.fields['Z CZYM STUDENT MIAŁ NAJWIĘKSZE PROBLEMY'],
'CZY JEST POSTĘP OD OSTATNIEGO CR': newItem.fields['CZY JEST POSTĘP OD OSTATNIEGO CR'],
'DURATION IN MINUTES': newItem.fields['DURATION IN MINUTES'],
'NOTKA': newItem.fields['NOTKA'],
'DZIAŁ': newItem.fields['DZIAŁ'],
'STATUS': { name: "WYPEŁNIONA" }
}
const table = base.getTable('STUDENTS LESSONS')
await table.updateRecordAsync(toUpdate.id, fieldsToUpdate)
await table.deleteRecordAsync(newItem.id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment