Aug 11, 2022 07:14 PM
Hello, I need some basic button scripting help if anyone is willing (at least I think it’s basic).
I have two tables:
In the ContactLog table I have the following relevant fields:
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!
Aug 11, 2022 08:19 PM
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
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'},
})
}