Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Cryptic error on basic record create with linked record attempt

Topic Labels: Scripting
Solved
Jump to Solution
2380 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Kosta_Kondraten
7 - App Architect
7 - App Architect

I am receiving a cryptic error when attempting to create a record using the code below:

// Change this name to use a different table
let table = base.getTable("Touchpoints");
//let ctable = base.getTable("Contact");

// Prompt the user to pick a record 
// If this script is run from a button field, this will use the button's record instead.
let record = await input.recordAsync('Select a record to use', table);

let billTillString = await input.textAsync('Bill Orders till which date? (format YYYY-MM-DD)');
//let notes = await input.textAsync('Any Notes to mention');

let billTillDate = new Date(billTillString);

/*
//newRecs[0]['id'] = 'recDYGIT7fj80tTAH';
//let namer = new Array('recDYGIT7fj80tTAH');

//let Contact = record.getCellValueAsString("Contact"); // Contact RecordID
//let recordID = record.getCellValueAsString("Contact RecordID");

//console.log("ID is: " + recordID);
*/
await table.createRecordAsync({
        'Start Date/Time': billTillDate,
        'Contact': [{id: 'recI7YlIh4jJkUiYT'}],
        'Notes': 'Sample Note'
    }); 

/*

console.log(billTillDate);


if (record) {
    // Customize this section to handle the selected record
    // You can use record.getCellValue("Field name") to access
    // cell values from the record
    console.log(record.id);
} else {
    output.text('No record was selected');
} */

https://share.getcloudapp.com/NQuWLz8y

It's also INCREDIBLY slow - any input or ideas would be much appreciated. Thank you!

P.S. I'm just trying to create a new record with a date which is inputted along with a linked record.

Video for context: https://share.getcloudapp.com/d5ugL4Z6

2 Solutions

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

You don't say the field type for your {Start Date/Time} field, but I'm guessing that it is a date field. You need to convert the date to an ISO 8601 string, per the documentation.

 

'Start Date/Time': billTillDate.toISOString(),

 

 

See Solution in Thread

Kosta_Kondraten
7 - App Architect
7 - App Architect

This issue is fixed, I updated to the following code and it's all working now 🙂

 

let table = base.getTable("Touchpoints");
let cTable = base.getTable("Contact");

let trecord = await input.recordAsync('Select a record to use', table);




let callBack = await input.textAsync('What is the callback date? (YYYY-MM-DD)');

let notes = await input.textAsync('Include any callback notes');

let callDate = new Date(callBack);
let recordID = trecord.getCellValueAsString("Email");



let query = await cTable.selectRecordsAsync();

// Replace "example@example.com" with the email address you want to search for
let emailToSearch = trecord.getCellValueAsString("Email");

let record = query.records.find(record => record.getCellValue("Email") === emailToSearch);

if (record) {
  // Do something with the record, such as log it to the console
  await base.getTable('Touchpoints').createRecordAsync({
        'Start Date/Time': callDate,
        'Notes': notes,
        'Type': { name: 'Call Back' },
        'Contact': [{id: record.id}]
    });
  console.log(record);
} else {
  console.log(`Record with email ${emailToSearch} not found.`);
}

See Solution in Thread

5 Replies 5
Kosta_Kondraten
7 - App Architect
7 - App Architect

https://share.getcloudapp.com/xQuRPZPP

Fore more context on the crash that happens on a linked record

kuovonne
18 - Pluto
18 - Pluto

You don't say the field type for your {Start Date/Time} field, but I'm guessing that it is a date field. You need to convert the date to an ISO 8601 string, per the documentation.

 

'Start Date/Time': billTillDate.toISOString(),

 

 

Thank you so much for your reply!

Unfortunately even when removing all references to Date the app still crashes. Video below provides more context:

https://share.getcloudapp.com/wbuDjr5g

Kosta_Kondraten
7 - App Architect
7 - App Architect

This issue is fixed, I updated to the following code and it's all working now 🙂

 

let table = base.getTable("Touchpoints");
let cTable = base.getTable("Contact");

let trecord = await input.recordAsync('Select a record to use', table);




let callBack = await input.textAsync('What is the callback date? (YYYY-MM-DD)');

let notes = await input.textAsync('Include any callback notes');

let callDate = new Date(callBack);
let recordID = trecord.getCellValueAsString("Email");



let query = await cTable.selectRecordsAsync();

// Replace "example@example.com" with the email address you want to search for
let emailToSearch = trecord.getCellValueAsString("Email");

let record = query.records.find(record => record.getCellValue("Email") === emailToSearch);

if (record) {
  // Do something with the record, such as log it to the console
  await base.getTable('Touchpoints').createRecordAsync({
        'Start Date/Time': callDate,
        'Notes': notes,
        'Type': { name: 'Call Back' },
        'Contact': [{id: record.id}]
    });
  console.log(record);
} else {
  console.log(`Record with email ${emailToSearch} not found.`);
}

Thank you so much! This did end up working - much appreciated!