logo

Creating and configuring display of filter folders using a script

This article describes creating and configuring the display of filter folders using a script.

A filter folder is created using standard features. Below is an example of a script for creating a filter folder.

Script without PublicAPI

Script text:

var admin = UserManager.Instance.Load(SecurityConstants.AdminUserUid);
var folderOffice = FolderManager.Instance.LoadOrNull(DocflowConstants.FolderOffice);
var folderIncoming = new InstanceOf<IFilterDocumentFolder>
                {
                    New =
                    {
                        CreationAuthor = admin,                        
                        Folder = folderOffice,
                        Name = SR.T("Incoming"),
                        ImageUrl = "/Content/Images/x16/in.png",
                        SortTypeId = 10,
                        SearchOnOpen = true,
                        Virtual = true
                    }
                }.New;
folderIncoming.Permissions.Add(new InstanceOf<IDmsObjectPermission>
                {
                    New =
                    {
                        DmsObject = folderIncoming,
                        PermissionId = EleWise.ELMA.Documents.PermissionProvider.DocumentViewPermission.Id,
                        TypeRoleId = CommonRoleTypes.User.Id,
                        User = admin
                    }
                }.New);
   
 folderIncoming.Permissions.Add(new InstanceOf<IDmsObjectPermission>
                {
                    New =
                    {
                        DmsObject = folderIncoming,
                        PermissionId = EleWise.ELMA.Documents.PermissionProvider.DocumentEditPermission.Id,
                        TypeRoleId = CommonRoleTypes.User.Id,
                        User = admin
                    }
                }.New);
 folderIncoming.Permissions.Add(new InstanceOf<IDmsObjectPermission>
                {
                    New  = 
                     {
                        DmsObject = folderIncoming,
                        PermissionId = EleWise.ELMA.Documents.PermissionProvider.DocumentManagerAccessPermission.Id, 
                        TypeRoleId = CommonRoleTypes.User.Id,
                        User = admin
                     }
                 }.New);
   
 folderIncoming.Permissions.Add(new InstanceOf<IDmsObjectPermission>
                {
                    New =
                    {
                       DmsObject = folderIncoming,
                       PermissionId = EleWise.ELMA.Documents.PermissionProvider.DocumentFullAccessPermission.Id,
                       TypeRoleId = CommonRoleTypes.User.Id,
                       User = admin
                    }
                }.New);
   
var documentFilter = (IDocumentExtFilter)InterfaceActivator.Create<IDocumentFilter>();
documentFilter.RegistrationCard = InterfaceActivator.Create<IRegistrationCardFilter>();
documentFilter.RegistrationCard.Flow = DocumentFlowType.Incoming;
documentFilter.RegistrationCard.Status = RegistrationCardStatus.Register;
folderIncoming.DocumentFilter = UniversalFilterSaver.Pack(documentFilter);
folderIncoming.Save();
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here

Namespaces:

using EleWise.ELMA.API;
using EleWise.ELMA.Documents.Models;
using EleWise.ELMA.Model.Filters;
using EleWise.ELMA.Security;
using EleWise.ELMA.Model.Services;
 

Script text:

var admin = PublicAPI.Portal.Security.User.Load(SecurityConstants.AdminUserUid);
var folderOffice = PublicAPI.Docflow.Folder.LoadOrNull(DocflowConstants.FolderOffice);
var a = PublicAPI.Docflow.Objects.Folders.FilterDocumentFolder.Create();
    a.CreationAuthor = admin;
    a.Folder = folderOffice;
    a.Name = SR.T("Incoming");
    a.ImageUrl = "/Content/Images/x16/in.png";
    a.SortTypeId = 10;
    a.SearchOnOpen = true;
    a.Virtual = true;
             
PublicAPI.Docflow.Permissions.AddViewPermission(a,admin);
PublicAPI.Docflow.Permissions.AddEditPermission(a,admin);
PublicAPI.Docflow.Permissions.AddManageAccessPermission(a,admin);
PublicAPI.Docflow.Permissions.AddFullAccessPermission(a,admin);
             
var documentFilter = PublicAPI.Docflow.Document.Filter().Filter;
             documentFilter.RegistrationCard = InterfaceActivator.Create<IRegistrationCardFilter>();
             documentFilter.RegistrationCard.Flow =  PublicAPI.Enums.Documents.DocumentFlowType.Incoming;
             documentFilter.RegistrationCard.Status = PublicAPI.Enums.Documents.RegistrationCardStatus.Register;
    a.DocumentFilter = UniversalFilterSaver.Pack(documentFilter);
    a.FilterColumnState = new List<string> { "Name", "CreationAuthor" };
    a.Save();
 

Now hide the Creation Date field, (which is added automatically according to the metadata) and add the Date Modified field. For this, you need to modify the GridState property of the filter folder. To learn more about the table state read this article.

//Create a state of document table
var gridState = GridState.CreateNew("Incoming", typeof(IDocument));
//Load the document type description
var documentMetadata = (EntityMetadata)InterfaceActivator.LoadMetadata<IDocument>();
//Find the description of the Creation Date property
var creationDateMetadata = documentMetadata.Properties.First(p => p.Name == "CreationDate");
 //Find the Creation Date column state
var creationDateState = gridState.ColumnStates.FirstOrDefault(c => c.UniqueName == creationDateMetadata.UidStr);
//Hide the Creation Date column
if (creationDateState != null)
     creationDateState.Hidden = true;
//Find the description of the Date Modified field
var changeDateMetadata = documentMetadata.Properties.First(p => p.Name == "ChangeDate");
//Find the Date Modified column state
var changeDateState = gridState.ColumnStates.FirstOrDefault(c => c.UniqueName == changeDateMetadata.UidStr);
//Display the column
if (creationDateState != null)
     changeDateState.Hidden = false;
 //Write the table state to the filter folder (first, you need to serialize the object)
folderIncoming.GridState = ClassSerializationHelper.SerializeObject(gridState);
 

Now set the list of columns for the advanced search. The filter has the FilterColumnState property.

folderIncoming.FilterColumnState = new List<string> { "Name", "CreationAuthor" };
 

After all the operations, save the filter folder.

folderIncoming.Save();