Skip to main content
Solved

createRecordAsync not creating a Record

  • Sep 8, 2021 10:57 PM UTC
  • 2 replies
  • 166 views

Forum|alt.badge.img+2

Can I get a second pair of eyes on my script? Expected behavior is that a user can click a button on any record in the “People” table, and it will create a record in the “Payouts” table, linked to People by a lookup field called “Person”

I don’t get any error messages when I run this script, but I also don’t get any new records in the “Payouts” table. And I’m the only user on the license, so I don’t think it would be a permissions error.

Can you see anything I’m missing? Thanks in advance!

const childTable = base.getTable('Payouts');
const parentTable = base.getTable('People');
const parentRecord = await input.recordAsync('Parent record', parentTable);
const linkField = 'Person';
const newRecordValue = parentRecord.getCellValue("Account Balance")*(-1);
console.log(newRecordValue);

childTable.createRecordAsync({'Amount': newRecordValue, linkField: parentRecord});

Best answer by kuovonne

Your syntax for the linked field is incorrect. You are not seeing the error message because you are not awaiting the createRecordAsync line, thus your script ends before it has a chance to report the error.

Try this …

await childTable.createRecordAsync({
    'Amount': newRecordValue, 
    [linkField]: [{id: parentRecord.id}],
});

View original
This topic has been closed for replies.

2 replies

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • Answer
  • Sep 9, 2021 12:01 AM UTC

Your syntax for the linked field is incorrect. You are not seeing the error message because you are not awaiting the createRecordAsync line, thus your script ends before it has a chance to report the error.

Try this …

await childTable.createRecordAsync({
    'Amount': newRecordValue, 
    [linkField]: [{id: parentRecord.id}],
});


Forum|alt.badge.img+2
  • Author
  • New Participant
  • Sep 9, 2021 2:57 AM UTC

Thank you! That did the trick.