Dataservice TextOption field

Scenario:
In the current solution I am working with we have implemented a custom approval process. an order should be approved by 2 authorizers and we assign each customer with 2 specific authorizers by setting them in 2 different TextOption fields.

When we delete an authorizer from the system we need to fetch all persons and removed the deleted authorizer from the field. So I have implemted a event listener that listens to PersonDeleted and the I use dataService to fetch the customers that had the deleted person as authorizer assigned to it.

Problem:
When I execute my dataService I get the following exception:
No field with id 'Authorizer1' and operator 'eq'.

Isn’t it possible to search for persons by TextOption-field? In this case how can I solve it?

My implementation of the dataService:

    List<Person> GetPersonsByFieldValue(string fieldId, string fieldValue)
    {
        using (var query = _dataService.CreateQuery<Person>())
        {
            var q = query.Filter(f =>
                f.Bool(boolFilter => boolFilter
                    .Must(must =>
                        must.Field(fieldId, "eq", fieldValue))
                ));

            return q.ToList();
        }
    }

Litium version: [7.4.2]

Hi,
Did you check which operators are avialable for TextOption field? See the opretor check example at https://docs.litium.com/documentation/architecture/data-service

Why don’t you use Boolean fields instead?
If you are creating 2 new fields (Authorizer1 and Authorizer2) then a true/false value on each item should fulfill that purpose or am I missing something?

This would give you what you need:

List<Person> GetPersonsByFieldValue(string fieldId, string fieldValue)
        {
            using (var query = _dataService.CreateQuery<Person>())
            {
                var q = query.Filter(f => f.Field(fieldId, "contains", fieldValue));
                return q?.ToList();
            }
        }

Thanks @steve.redstorm. Used your suggestion and added an additional condition on the result to achieve the result of an “eq”-operator.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.