[Deprecated] Exclude databases from search via script

Hi guys,

Found the workaround to exclude databases from search via API.

Since we have hundred databases, we want to be easily able to exclude/include. I’m trying to create buttons for that.

So I have two buttons: include and exclude. I have the APP_NAME/TYPE_NAME stored in a database → field name = SpaceDatabase

I’ve managed to write the script that indeed excludes the database from search; but in this example the Space/Database is fixed (DB acceleright/Documentatie).

const http = context.getService("http");

await http.postAsync("https://acceleright.fibery.io/api/commands", {
    headers: {
        "Content-type": "application/json",
        Authorization: "Token xxx",
    },
    body: [
        {
            command: "fibery.schema/batch",
            args: {
                commands: [
                    {
                        command: "schema.type/set-meta",
                        args: {
                            name: "DB acceleright/Documentatie",
                            key: "search/disabled",
                            value: true,
                        },
                    },
                ],
            },
        },
    ],
});

What I’m trying to do, is getting the variable SpaceName in this script. It shouldn’t be that hard but I got stuck since I’m not a script queen :see_no_evil:

Does somebody has the magic script for me? Tried several things but with no good result.

Thanks!

If you want to use variables in a command, you need to pass them in as parameters, e.g.

commands: [
    {
        command: "schema.type/set-meta",
        args: {
            name: "$database",
            key: "search/disabled",
            value: true,
        },
        params: {
            "$database": SpaceDatabase
        }
    },
],

This assumes you have previously executed a function to set the value for SpaceDatabase.

P.s. you don’t need to use the http call to execute a command in this way. The Fibery service includes a function: ‘executeSingleCommand’ which is much easier to use, and doesn’t require storing the API key in the script e.g.

const fibery = context.getService('fibery');
await fibery.executeSingleCommand({
    command: "fibery.schema/batch",
    args: {
        commands: [
            {
                command: "schema.type/set-meta",
                args: {
                    .
                    .
                    .
                    .

Awesome, thanks again :star_struck:!

I don’t know why, but it didn’t worked if I used the ‘params’ as you mentioned.

However, this script works:

const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    const SpaceDatabase = entity["SpaceDatabase"];
    await fibery.executeSingleCommand({
        command: "fibery.schema/batch",
        args: {
            commands: [{
                command: "schema.type/set-meta",
                args: {
                    name: SpaceDatabase,
                    key: "search/disabled",
                    value: true,
                }
            }]
        }
    });
};

Currently I’ve made a button to run the script and exclude/include a database from search.

Ideally I want to have a database with all active databases/spaces in the workspace. So that you have an up to date overview and can use the buttons to inlude/exclude from search. We would then also use that database to link our documentation + SOP’s to a specific database/space.

Would be awesome if this would be native functionality for admins or app in Fibery.

But for now: is there maybe is a way via script (+ on schedule automation?) to have an overview of all active databases/spaces in a workspace (plus ideally if search/disabled is true or false)?

https://the.fibery.io/@public/Public_Roadmap/Roadmap_Item/Exclude-a-Database-from-search-results-177
Does this relevant on this ? I saw State: Ready for dev already

Thanks! It was ‘Icebox’ at the beginning of this week because there was a workaround. But I think they may changed something after my chat with support :slight_smile:

But even if the ‘normal solution’ goes live, I still like to have a complete overview of all spaces/databases in our workspace.

Since we can then easily fix permissions via groups, link our docs en SOPs and have an overview of which databases are excluded from search yes/no.

If you only have a setting per database, then it’s kinda hard to have overview since we have 100+ databases.

The “normal solution” is here: Jan 18, 2024 / Entity permissions, exclude DBs from search.

If you have used the script, the DBs you excluded should remain excluded.

If you execute the script now, it won’t have any effect, since we are using a different API. The script has been a great proof of concept, but now there are ∞−1 workarounds in Fibery :sweat_smile:

1 Like