Help

Re: Help with a script please!

Solved
Jump to Solution
5836 6
cancel
Showing results for 
Search instead for 
Did you mean: 
Dennis_Petrou
7 - App Architect
7 - App Architect

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!

1 Solution

Accepted Solutions

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.

See Solution in Thread

10 Replies 10

I think you want to use selectRecordAsync.

thank you! I just tried that, and now get this:
ReferenceError: selectRecordAsync is not defined
at main on line 2

You should publish your new version of the failing code.

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!');

If you look at your script in the editor, the location of the error is made obvious with the red underline.

image

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.

image

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);

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"];

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.

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:

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.