Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Aug 24, 2022 10:47 AM
Hello. Let me preface this by saying I am not great at scripts, so your patience and clear explanations would be greatly appreciated.
We currently have a script (no idea who wrote it ages ago) in one of our tables that works by the pressing of a button. I am trying to get the same script to work by triggering it with a checkbox so I can use it in an automation. Thinking I could just copy/past the script, but that clearly doesn’t work. I get the error :
TypeError: input.recordAsync is not a function
at main on line 2
I know I have to make some changes for it to work properly, I’ve seen similar responses but couldn’t figure out exactly what to do. The original working script that is currently triggered by a button is:
let mapperschedule = base.getTable("Mapper Schedule");
let record = await input.recordAsync('Pick a record', base.getTable('Mapper Schedule'));
let topaste = record.getCellValue('Update Mapper Schedule Name - To Paste');
let name = record.getCellValue('Name');
output.markdown(topaste);
if(topaste!=""){
await mapperschedule.updateRecordAsync(record.id,{
'Name': topaste
});
}
output.markdown('# Done!');
Any help would be greatly appreciated!
Solved! Go to Solution.
Oct 26, 2022 09:15 AM
Oops. I had a typo too (typing on my phone). The quotes are wrong in this line. I went back and fixed my original post.
Aug 24, 2022 11:04 AM
I think you want to use selectRecordAsync
.
Aug 24, 2022 11:25 AM
thank you! I just tried that, and now get this:
ReferenceError: selectRecordAsync is not defined
at main on line 2
Oct 25, 2022 02:44 PM
You should publish your new version of the failing code.
Oct 25, 2022 03:59 PM
thanks, here it is
let mapperschedule = base.getTable("Mapper Schedule");
let record = await selectRecordAsync('Pick a record', base.getTable('Mapper Schedule'));
let topaste = record.getCellValue('Update Mapper Schedule Name - To Paste');
let name = record.getCellValue('Name');
output.markdown(topaste);
if(topaste!=""){
await mapperschedule.updateRecordAsync(record.id,{
'Name': topaste
});
}
output.markdown('# Done!');
Oct 25, 2022 04:31 PM
If you look at your script in the editor, the location of the error is made obvious with the red underline.
The documentation for selectRecordAsync indicates that it is a method of a table and no table is declared for this method in your code. Essentially, the script is struggling by asking - … you want to select a record from where exactly?
The example in the documentation shows how to use this method.
As such, you need to place the table object in front of the select method like this.
let record = await mapperschedule.selectRecordAsync('Pick a record', base.getTable('Mapper Schedule'));
You can also simplify your code for this by referencing the table object in the second parameter like this:
let record = await mapperschedule.selectRecordAsync('Pick a record', mapperschedule);
Oct 25, 2022 08:30 PM
I think you mean
let record = await mapperschedule.selectRecordAsync(recordId,
{fields: ["Update Mapper Schedule Name - To Paste", "Name"]})
Of course you would also need to set the variable recordId
from an input variable.
let inputConfig = input.config();
let recordId = inputConfig["recordId"];
Oct 26, 2022 04:06 AM
Yes! Many things I intend to come out of my mouth never seem to. I’m swamped and I waited for a long time for someone to respond to @Dennis_Petrou and when it was apparent no one would, I gave it a very quick stab. Thanks for helping him get over the hurdle.
Oct 26, 2022 08:30 AM
Good Morning! Thanks everyone for the help. I changed the code using your suggestions (I think I followed it correctly) to:
let mapperschedule = base.getTable("Mapper Schedule");
let inputConfig = input.config();
let recordId = inputConfig["recordId'];"]
let record = await mapperschedule.selectRecordAsync('Pick a record', mapperschedule);
let topaste = record.getCellValue('Update Mapper Schedule Name - To Paste');
let name = record.getCellValue('Name');
output.markdown(topaste);
if(topaste!=""){
await mapperschedule.updateRecordAsync(record.id,{
'Name': topaste
});
}
output.markdown('# Done!');
now I am getting an error that says : TypeError: Cannot read properties of null (reading ‘getCellValue’)
at main on line 5
Sorry if I’m not understanding correctly, this is like a different language to me :slightly_smiling_face:
Oct 26, 2022 09:15 AM
Oops. I had a typo too (typing on my phone). The quotes are wrong in this line. I went back and fixed my original post.