Created
December 3, 2022 14:58
-
-
Save Przemocny/f8a1a44c136897a83f93bc7738feb797 to your computer and use it in GitHub Desktop.
airtable.mergeEntriesOnFormSubmit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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