logo

Using filters by object instances in scripts

Often you need to find object instances that satisfy certain parameters. The best way of solving this task is to use filters.

Assume you need to find all the users with the same last name, e.g. Smith. In this case, the script will be as follows.

Script with PublicAPI

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

Namespaces:

using EleWise.ELMA.API;

Script:

//create a filter by instances of the User object, by last name and write the results to the Users variable of the User type with the List link type
context.Users.AddAll(PublicAPI.Portal.Security.User.Filter().LastName("Smith").Find());

Script without PublicAPI

Namespaces:

using EleWise.ELMA.Services;
using EleWise.ELMA.Security.Models;

Script:

var a = new InstanceOf<IUserFilter> { //create a filter
    New = {
     LastName = "Smith",   //search parameter
     }
    }.New;
    // write the results to the Users variable of the User type with the List link type
    context.User.AddAll(EntityManager<User>.Instance.Find(a, null)); 
 

You can use filters in scripts for user objects too. Assume there is a user object Branch Office, which stores the list of company's branch offices and data on them. Using a filter, you need to find only those offices that are in London, i.e. the instances of the Branch Office object, whose string field City has the London value. To be able to use filters for custom objects in scripts, the following conditions must be met:

 1. In the settings of the object property, which will be used for filtering, on the Advanced tab, check the Participates in search (filter) box:

 

2. After you check this box, a notification will be displayed. Click OK to continue:

There is another way to enable filter generation: enable the advanced mode in the Designer settings, go to the Advanced tab of the object settings and check the Generate Filter box:

The script will be like this.

Script with PublicAPI

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

Namespaces:

using EleWise.ELMA.ConfigurationModel;
using EleWise.ELMA.API;

Script text:

//create a filter by instancs of the Branch Office object, by the City field and write the results to the variable OfficesInLondon of the Branch Office type with the List link type
context.OfficesInLondon.AddAll(PublicAPI.Objects.UserObjects.UserFilial.Filter().City("London").Find());

Script without PublicAPI

Namespaces:

using EleWise.ELMA.Services;
using EleWise.ELMA.ConfigurationModel;

Script text:

var a = new InstanceOf<IFilialFilter> {  //create a filter
       New = {
          City = "London",      //search parameter
          }
       }.New;
       //write the results to the variable OfficesInLondon of the Branch Office type with the List link type
       context.OfficesInLondon.AddAll(EntityManager<Filial>.Instance.Find(a, null));