Programmatically Using Section Folder Filters in Processes or Server-Side Code in Creatio

A useful way to allow a user to control the filters for some server-side operation or process is to allow them to select a folder for your back end code to use for filtering the data. There’s a few things you need to do to retrieve the filters for a folder. This article will provide some reusable code for you to retrieve the filters for a section folder to use as filters for a new EntitySchemaQuery of your own.

To retrieve the filter conditions for a folder, you’ll need to get the folder’s binary SearchData column data, the encode to a string, then deserialize them, and finally convert the deserialized filters to valid EntitySchemaQuery filters. Here’s some reusable code you can use to do all of this. To use, change the first two lines to the section the folder is for and the Id of the folder itself (for example, if this is an Account section folder, the Id of the folder from the AccountFolder table). Also, make note that you’ll also need to include a using directive for the Terrasoft.Nui.ServiceModel.Extensions – which provides the BuildEsqFilter extension method we’re using in the C# code below. Note, all you should need to change are the first two lines of code, the rest can stay as-is (up until the comment with the —— that uses the filters as a sample)

// set these as needed for the section and the Id of the folder
var sectionName = "Account";
var folderId = someAccountFolderId;

// get folder SearchData
var folderSchema = UserConnection.EntitySchemaManager.GetInstanceByName(sectionName + "Folder");
var esq = new EntitySchemaQuery(folderSchema);
var dataCol = esq.AddColumn("SearchData").Name;
var folderData = esq.GetEntity(UserConnection, folderId).GetBytesValue(dataCol);

// convert filter data to esq filters
var serializedFilters = System.Text.Encoding.UTF8.GetString(folderData, 0, folderData.Length);
var dataSourceFilters = Terrasoft.Common.Json.Json.Deserialize<Terrasoft.Nui.ServiceModel.DataContract.Filters>(serializedFilters);

// MUST INCLUDE using Terrasoft.Nui.ServiceModel.Extensions;
var folderFilters = dataSourceFilters.BuildEsqFilter(UserConnection.EntitySchemaManager.GetInstanceByName(sectionName).UId, UserConnection);

// ---------------------------------------------------
// now can include folderFilters as filters in new esq

var accountEsq = new EntitySchemaQuery(UserConnection.EntitySchemaManager, "Account");
accountEsq.AddColumn("Id");
accountEsq.Filters.Add(folderFilters); // using the filters from the folder
var accounts = accountEsq.GetEntityCollection(UserConnection);

Note, the comment in the code about including a using directive for Terrasoft.Nui.ServiceModel.Extensions. If you’re using this in a source code schema, simply add the using directive. If you’re using this in a process, you’ll need to add this on the Methods tab of the process properties, as shown below

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Ryan Farley
Ryan Farleyhttps://customerfx.com/article/author/ryanfarley/
Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

7 COMMENTS

    • If you’re referring to getting the selected filters for a Freedom UI list, I’m not sure, but I am pretty sure there is likely an attribute for those that you could find via debugging.

  1. When adapting this code, why might I get the below error pointing at UserConnection.EntitySchemaManager in the line `var folderSchema = UserConnection.EntitySchemaManager.GetInstanceByName(sectionName + “Folder”);`

    Error: An object reference is required for the non-static field, method, or property ‘UserConnection.EntitySchemaManager’

    Has something changed around UserConnection and its properties? Or does my C# class have to inherit from something it doesn’t currently inherit from?

    • It sounds like the UserConnection is null. Where are you using this code? A configuration web service, an anonymous service, or process script task, and if so, running from a timer? How is the UserConnection being retrieved?
      Ryan

    • I was trying to use it in some general C# class, but I see now that this way of getting an EntitySchemaManager is actually using a Property called UserConnection defined on the class rather than accessing a static property of the UserConnection class. Do you have any ways of getting a UserConnection/SystemUserConnection/AppConnection in a general C# class? Rather than having to have it passed in some way such as through a constructor or method’s parameters?

      In my current use case, I need to run some server ESQ when a class is initialised. The class inherits from the base class BaseEntityEventListener.

    • For a C# class, you’d typically have a constructor that has a param for a UserConnection that you’d pass into the class when you use the class. However, for an Entity event listener, the UserConnection is passed in via the EventArgs argument to the method you’re overriding.

    • Essentially, something like this:

      public override void OnDeleted(object sender, EntityAfterEventArgs e)
      {
          base.OnDeleted(sender, e);
          var entity = (Entity)sender;
          var userConnection = entity.UserConnection;
      }

LEAVE A REPLY

Please enter your comment!
Please enter your name here

AI Readiness Checklist for CRM Teams: Is Your CRM System Ready for AI?

Before using AI in Creatio, make sure your CRM data, users, processes, and automation foundation are ready. Use this practical AI readiness checklist for CRM teams.

Build Your Creatio AI Skills with the 2026 AI Summer Program

Join Creatio’s free 2026 AI Summer Program to learn how to identify, build, deploy, and manage AI agents.

Creatio 10x Is Coming: Join the Webinar to Explore the Future of AI-Native CRM

Learn what's new in Creatio 10x and how AI-native CRM, agentic AI, and no-code automation are shaping the future of customer relationship management. Join the upcoming webinar and discover what's next.

Creatio Unlimited Pricing Explained: AI Packages, Costs, Pros & Cons

Learn what Creatio’s new Unlimited pricing model includes, what it doesn’t include, how AI Action packages work, and the pros and cons for businesses evaluating Creatio.

Using the AI Prompt to Create Dynamic Folders in Creatio

Using Creatio's AI prompt to create the filter for a dynamic folder works best if you specifically ask for that, and if you are as clear and direct as possible about the filtering, conditions.

Related Articles

AI Readiness Checklist for CRM Teams: Is Your CRM System Ready for AI?

Before using AI in Creatio, make sure your CRM data, users, processes, and automation foundation are ready. Use this practical AI readiness checklist for CRM teams.

Build Your Creatio AI Skills with the 2026 AI Summer Program

Join Creatio’s free 2026 AI Summer Program to learn how to identify, build, deploy, and manage AI agents.

Creatio 10x Is Coming: Join the Webinar to Explore the Future of AI-Native CRM

Learn what's new in Creatio 10x and how AI-native CRM, agentic AI, and no-code automation are shaping the future of customer relationship management. Join the upcoming webinar and discover what's next.

Creatio Unlimited Pricing Explained: AI Packages, Costs, Pros & Cons

Learn what Creatio’s new Unlimited pricing model includes, what it doesn’t include, how AI Action packages work, and the pros and cons for businesses evaluating Creatio.

Related Videos