Can someone please help me extract the filename from an Attachments column?

Hello!

I’ve been trying to make a JS script but with no success, I either get undefined or syntax error.

The intention is to extract the filename from the attachments column (and to paste the extracted name into another column).

I already read the SeaTable programming manual and the GitHub examples.

Thank you for your help and attention!

I’m sorry for any inconvenience!

Let’s say you have such a table


And you would like to extract the filename of the 1st object in the “File” column and write it into the column “Filename”. So you create a button column and let it execute the following JavaScript:

const table = base.context.currentTable;
const row = base.context.currentRow;

base.modifyRow(table, row, {'Filename': row.File[0].name});

If you are really fresh to JavaScript in SeaTable, you could use the following script to study the structure of the rows:

const rows = base.getRows('Table1', 'Default View');
output.text(rows)

And then click on “Run script”. In the console you’ll then see the data structure. From there, you can extract anything from the returned JSON.

1 Like

Hello!

Thank you for your answer and for solving my problem.

I was not understanding how to “declare” or “call” the objects correctly, I mean specifically, the part that proceeds table, row, which is {'Filename': row.File[0].name}); even that I previously used this:

to understand the structure.

Anyway, I will try to learn as much as possible from the help I asked for, to better understand how to properly “read” and structure the other scripts.

Thank you for your help and attention!

I’m sorry for all the inconvenience!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.