Download all attachments via button

Use case:
After an invoice (database, with original PDF attached to entity) gets approved for payment, an additional PDF is generated within the entity which contains all necessary information for further processing (-> single pager with summary of invoice information plus the approvals (date + person) and cost center).

I would like to quickly open the invoice + approval page of multiple approved invoices at one, with my system viewer (Adobe Reader Pro) and print it.

Is there anyone who could help in creating a script that would open all attached files of an entity with the default system program?

Trying to follow the api documentation:

const Fibery = require('fibery-unofficial');
const fibery = new Fibery({host: "", token: YOUR_TOKEN});

const files = await fibery.entity.query({
  'q/from': 'Cricket/Player',
  'q/select': [
    { 'Files/Files': {
      'q/select': ['fibery/secret'],
      'q/limit': 'q/no-limit'
    } }
  'q/where': ['=', ['fibery/id'], '$entity-id'],
  'q/limit': 1
}, { '$entity-id': '20f9b920-9752-11e9-81b9-4363f716f666' });

Grab the secrets:

[ { 'fibery/id': '20f9b920-9752-11e9-81b9-4363f716f666',
    'Files/Files': [
    { 'fibery/secret': 'a71a7f30-9991-11e9-b8d4-8aba22381101' },
    { 'fibery/secret': 'c5815fb0-997e-11e9-bcec-8fb5f642f8a5' } ] } ]

Download Files using these secrets:

const Fibery = require('fibery-unofficial');
const fibery = new Fibery({host: "", token: YOUR_TOKEN});

await'a71a7f30-9991-11e9-b8d4-8aba22381101', './playing.jpg');
await'c5815fb0-997e-11e9-bcec-8fb5f642f8a5', './resting.jpg');

Am I correct to assume that:

  • Cricket → Space, Player → Database
  • I need to save the queried entity ID to a variable, which I use to query for the secret
  • I need to save the secret to a variable to download the files using variable as placeholder of the secret in the example

Is there anyone who could help me with the code, or comment on my assumptions?

Thanks a lot in advance for any help!

Yes that is correct.
Syntax in fibery for all custom fields is <Space>/<Database>. Keep in mind that fields like id, and name are not custom.

to save an id in a variable you can use use const syntax.

const entityId = "20f9b920-9752-11e9-81b9-4363f716f666";

and later refer/use to it like this:

{ '$entity-id': entityId }

Make sure that const is declared before the place where you want to refer/use to it.

Hi @Eren_Turgut

I’m not sure that get what you want achieve in your use case. Script written for a Button or Automation is running on server side sandbox and has no any connection with your Browser environment.

script that would open all attached files of an entity with the default system program

So this one cannot be achieved.

Thank you both for your help.

So I’ve tried to do it but getting an error message:

Download all files is failed.
Failed to execute Action “Script”: Cannot read property ‘query’ of undefined

Can someone figure out which part is wrong? This is what my code looks like:

> const fibery = context.getService('fibery');
> const entityid1 = args.currentEntities[0].Id;
> const files = await fibery.entity.query({
>     'q/from': 'Finance and Controlling/Invoice',
>     'q/select': [
>         'fibery/id',
>         {
>             'Files/Files': {
>                 'q/select': ['fibery/secret'],
>                 'q/limit': 'q/no-limit'
>             }
>         }
>     ],
>     'q/where': ['=', ['fibery/id'], '$entity-id'],
>     'q/limit': 1
> }, { '$entity-id': entityid1 });

I guess I have to query since the args.currentEntitites doesn’t include information on Files and their secrets, but can’t run this according to the API docs.

Hi @Viktar_Zhuk,

But it does send commands from the server side sandbox to my browser, no? And the browser has a connection to the browser environment?
I guess the “open with system program” part could be set up within the browser settings, so just being able to download with the press of a button would be good enough.

No it works in completely different way. With this script you can interact with Fibery backend (e.g. pull data / update field value) and with other remote systems (pull, submit data). However you (or script) has no access to the Browser whatsoever.

You edit script which will be stored in some remote server.
When you click a Button, UI sends requests to that remote server with some enumerated args and gets back simplistic success / error response.

Abilities you are talking about is not inherently impossible but not implement in any way atm.

What I am asking for is a simple download of files:

  • determine entity ID (done)
  • determine secret for each file within said entity (failing to query for the secrets of files)
  • download file via command: await for each secret.

Am I missing something here? There is a clear section on how to download, upload files and attach them to entitites (which I’m gonna use in a second step to copy File from one entity to the other).

But I can’t even run the simplest query:

const users = await fibery.entity.query({
“q/from”: “Finance and Controlling/Invoice”,
“q/select”: [“fibery/id”],
“q/limit”: 1

which is supposed to give me the ID of 1 Invoice entity

The examples at are not intended to be used directly in automation scripts. It is intended for querying/manipulating data in a Fibery workspace using an external agent.

The guide for scripting is here: . | Fibery
But as @Viktar_Zhuk said, scripting takes place on the server side, so it cannot push things to the browser.

1 Like

Ok thank you for the clarification.

It should however be possible to copy files to other entitites, as everything can happen server-side, no?

Use case:
Invoices come in via email.
Within the Email/Message database there is a button “Create invoice”, which prompts the user for some input (invoice date, number, amount, and so on) and then creates an entity in the Finance/Invoice database.

From my understanding of the backend, there is a separate storage for files, and each database utilizing files just gets another entity collection field, which basically references to that file via file’s ID and secret.

Now as we can’t leave the server environment, I guess what should be possible is to add an entity to the collection field (files) with the ID and Secret of an already existing file.

executeSingleCommand(command: FiberyCommand) might be needed for specific commands but I don’t see any reason to leave server environment for this to be possible, am I wrong here?

Please create a separate ticket for new enquiry to avoid any misunderstanding for other community members.

1 Like

Will do, thanks and sorry for the troubles.

1 Like