Help

Script to send a Webhook containing field from specific View

Topic Labels: Automations
Solved
Jump to Solution
2145 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Jub
4 - Data Explorer
4 - Data Explorer

Hi everyone!

This Script is working greate to send a webhook containing table fields in an automation.

I'm trying chaneg it to send a only fields from a specific view.

I tried to change and adjust it to fit a certain View. I added "let view = table.getView("MyView");" and changed all the Table References to View References but I get an error message:

"TypeError: Cannot read properties of undefined (reading 'length')".

As I am new in coding, Can you tell what is missing?

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

In scripting, a view does not have a “fields” property listing the visible fields. Thus the lines containing view.fields.length and view.fields[i] won’t work. 

You will need to hardcode the list of fields that you want. 

See Solution in Thread

3 Replies 3
Jub
4 - Data Explorer
4 - Data Explorer

That is what I tried:

 

let table = base.getTable("MyTable");

let view = table.getView("MyView");

let webhookUrl = "https://hook.eu1.make.com";

let inputConfig = input.config();

console.log(inputConfig);

let queryResult = await view.selectRecordsAsync({});

console.log(queryResult);

let record = queryResult.getRecord(inputConfig.recordID);

console.log(record); let recordObject = {};

for (let i = 0; i < view.fields.length; i++) { recordObject[view.fields[i].name] = record.getCellValueAsString(view.fields[i].name) } console.log(recordObject);

let response = await fetch( webhookUrl, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(recordObject) } );

kuovonne
18 - Pluto
18 - Pluto

In scripting, a view does not have a “fields” property listing the visible fields. Thus the lines containing view.fields.length and view.fields[i] won’t work. 

You will need to hardcode the list of fields that you want. 

OK I undertand a bulk field view export is not possible.

@kuovonne thank you very much!