Help

Create linked child record with predefined inputs from script

1509 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_Desilets
4 - Data Explorer
4 - Data Explorer

Hello, I need some basic button scripting help if anyone is willing (at least I think it’s basic).

I have two tables:

  • Customers (parent table with all information related to the customer)
  • ContactLog (child table showing all of the past interactions with the customer).

In the ContactLog table I have the following relevant fields:

  • CustomerID (linked record field type back to the Customers table)
  • DateContacted (Date field type)
  • ContactType (single select with options such as “Call”, “Email”, and “Text”)
  • ContactResult (single select with options such as “Voicemail”, “No Answer”, and “Answered”)
  • Notes (long text field type).

Whenever we interact with a customer we add it to their contact log so that we have visibility across the company on conversations with customers. An example would be in the record for customer John Smith I add a linked record from him to a new record in the contact log with the DateContacted (8/11/2022), ContactType (Call), and ContactResult (Voicemail).

I am trying to create a script for a button that when pressed will automatically create a new linked record in the ContactLog table for that customer with predefined variables. Ultimately I would like to create buttons for each of the most common types of ContactLog records that we input on a regular basis to cut down on time and input errors, so a button that creates a new log for an email sent today, or a text message sent today.

I’ve seen some example scripts that do similar things such as the template for creating child records but I’m not looking for the button to prompt me on what to input, I want each button to create that predefined record with just the one click. Unfortunately, javascript is a little beyond me and I’ve been reading through tutorials on W3 today trying to figure it out but it’s just beyond me at this point.

Any help/tips/direction would be greatly appreciated!

1 Reply 1

That’s quite easy, but you may struggle a lot with proper input format for different field types, so I’m helping with that.
Also, 3*3 options means 9 buttons and 9 different scripts - not a best way. at least, you may add checkbox
image

image

that’s for start, the rest is up to you

const source=base.getTable('Customers')
const target=base.getTable('CustomerLog')
const rec=await input.recordAsync('',source);
if (rec){
await target.createRecordAsync({
    "CustomerName": rec.getCellValue('Name'),
    'CustomerID':[{id:rec.id}],
    'DateContacted': new Date().toISOString().slice(0,10),
    'ContactType':{'name':'Call'},
    'ContactResult':{'name':rec.getCellValue('answered?')? 'Answered':'Nope'},
    })
}