logo

Getting subfolders of the selected folder using a script

Assume there is a folder, and you need to get the list of its subfolders. You can find the Id of a folder on the page of this folder: it is the last number in the browser URL bar. To search subfolders, create a filter with a search parameter (in this case, the Id of the parent folder) and apply it to objects of the Folder type.

Script with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive. 

Add namespaces:

using EleWise.ELMA.API;
using EleWise.ELMA.Documents.Models;

Script text:

var children = PublicAPI.Docflow.Folder.GetAllChildren(PublicAPI.Docflow.Folder.LoadOrNull(36)).OfType<IFolder>().ToList();

Script without PublicAPI

For the script to work correctly, add namespaces:

using EleWise.ELMA.Documents.Managers;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Services;
Script example:
//creating a filter
var filter = new InstanceOf<IDmsObjectFilter> {
New = {
         //filter criterion - the parent folder; load it by id
         Folder = (Folder)FolderManager.Instance.LoadOrNull(10),                    
      }
}.New;
//apply the filter to the Folder objects, thus getting the list of the parent folder subfolders
var folders = EntityManager<Folder>.Instance.Find(filter, null).ToList();
As the result of the script execution, the local variable folders will contain the required list of subfolders. You can rewrite it to a context variable or process in the script using the specified local variable.