MemberOfCollection (Column displaying all collections containing an item)

This script column displays a semicolon-separated list of all collections containing the file or folder. If the item is not a member of any collection, <none> is displayed.

How to set up and use

:one: Save ColumnMemberOfCollection.js.txt to   

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: Toggle the column with

Set COLUMNSTOGGLE="scp:MemberOfCollection/MemberOfCollection(!,a,0)"

Things you might enjoy reading

How to use buttons and scripts from this forum

The script's inner workings

JScript
function OnInit(initData) {
    initData.name = 'MemberOfCollection';
    initData.version = '2025-01-30';
    initData.url = 'https://resource.dopus.com/t/memberofcollection-column-displaying-all-collections-containing-a-file/54331';
    initData.desc = 'Display all collections containing this file';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.method = 'OnColumn';
    col.name = 'MemberOfCollection';
    col.label = 'MemberOfCollection';
    col.header = 'MemberOfCollection';
}

function OnColumn(scriptColData) {
    var fsu = DOpus.FSUtil();
    var arrColl = [];
    var nameColl = '';
    var itemPath = String(scriptColData.item);

    var re = /^coll:\/\/([^\/]+).*/;

    var folderEnum = fsu.ReadDir('coll://', 'r');
    while (!folderEnum.complete) {
        var folderItem = folderEnum.Next();

        if (folderItem.is_dir) {
            var tmp = String(folderItem).match(re);
            if (tmp && tmp.length == 2) {
                nameColl = tmp[1];
            }
        }

        if (String(fsu.Resolve(folderItem)) != itemPath) continue;

        arrColl.push(nameColl);
    }
    folderEnum.Close();

    scriptColData.value = arrColl.length ? arrColl.join(';') : '<none>';
}
4 Likes

Thanks Alex for this script!

Unfortunately it does not yet work on my side. Script is installed, I can see it under

And the button is in place. When toggeling the button, the new column is enabled but there is no content for those files I know they are collection members.

Please have a look at this collection item:

When opening this location and pressing the button, I see this result:

Can you please have another look into the coding?

Could you add a few files to a collection via

Copy CREATEFOLDER=coll://test123

and check if the column shows the collection?

How did you create the multi-level collection from your screenshots?

Judging by the colors, you seem to have added folders as well.

Here, the same image without too much blurring:

There are no folders within the collection, at least not here, but I've got other collections which contain subfolders (collections). The current collection just has office documents saved.

The "multi-level" is done by simply ordering or grouping of the lister, nothing fancy here.

Great idea for a column! Thanks!
But wouldn’t it be better to enumerate the collections just once?

@Micky does this works?
ColsMember.opusscriptinstall (1.9 KB)

There's an option in the script config to also show items as members, even when they are not, as long as their parents are.
(Some people seem to get confused by expanded folders in collections)

EDIT: I tweaked the script a bit to avoid repetitive parent matches.

I'm not sure. How will the column "ColsMember" be populated with collection names?
I've tried, similar to lxp's button above, to add a new one with command:

Set COLUMNSTOGGLE="scp:ColsMember/ColsMember(!,a,0)"

Am I correct doing so?
At least the button shows/hides the new column, but nothing happens, no value (collection name) in the column so far.

Steps:

  • I've focused a lister with a file that is known to be a member of a collection.
  • I'm pressing the button, the columen "ColsMember" gets visible.
  • Nothing happens, even the script log is missing although the script itself seems to log sthg.

I haven't tested the lxp script yet, but mine should show you the collection's name(s), and if they are subcollections, show you a path with all the parent collections. In an infotip, it will display this same info but separated into lines instead of a semicolon.
So I'm not sure what the problem could be here. At least on my end, I've tested the column with both folders as members and sub collections.
You can change in script config the log level to debug to get a more detailed view of what is happening. And send me the script output by PM, if you are willing, of course.

OK, so I've changed the script's option to output debug logs instead of warnings only.

After pressing my button to switch on or off or vice versa, the new column, introduced by your script, nothing happens.

Neither any log entry nor any text within the new column.

Perhaps another approach for debugging: Does showing the column alone fill the column or is there anything left to be done to trigger the script?

Edit: Had to restart DO for the new option to be active. Now I see some logs, but nothing within the column yet.

It seems that the log gets written only upon restarting. If I re-read you post above, this is
done by purpos, means however, when adding a new collection member to any of my collections, the new column won't display the newly assigned collection, right?

It only needs a refresh, not a restart.

Correct, can acknowledge this :ok_hand:

I tried to recreate the scenario from your screenshot above.

  • Kundendiens is a folder added as a subcollection to SAP.
  • You can see that the ColsMember column correctly shows the collection name tree.
  • I also tried creating the subcollections manually and then adding just the files. Same result.
  • It will also work if you add Kundendiens to SAP as a member and match folder subitems in script config is set to True.

So I really don’t know why it’s not working on your end. I can't do anything else without the log, sorry.

@lxp @errante
Sorry for confusion, my bad.

It seems to work fine anytime, however, with a big delay.
When enabling the appropriate column, nothing happens at first. After a while, the column gets populated successfully.

E.g. the output of lxp's script:

Thanks for your support @both

Update 2025-01-30

  • Added support for folders
1 Like