Using ICriteria and Not to exclude records in SalesLogix

In SalesLogix you can use the Sage.Platform.Repository.ICriteria class to query the entity model using standard ICriteria.  One thing I have been asked in the past is how do you exclude certain conditions?  A common example might be show me all of the non-closed tickets for a contact, where being closed is denoted by a status=”Closed”.  In this scenario you only want a condition similar to status<>’closed’.  This can be done using the .Not method which accepts as an input a standard parameter to exclude.  Lets take a look at the code:

RepositoryHelper<Sage.Entity.Interfaces.ITicket> repository = EntityFactory.GetRepositoryHelper<Sage.Entity.Interfaces.ITicket>();

Sage.Platform.Repository.ICriteria criteria = repository.CreateCriteria();
criteria.Add(repository.EF.Eq("Contact.Id", contact.Id.ToString()));
criteria.Add(repository.EF.Not(repository.EF.Eq("StatusCode", "Closed")));

result = criteria.List<Sage.Entity.Interfaces.ITicket>();

You can see the entity factory EF.Not used above which has passed in a EF.Eq condition looking for “Closed“ statuses.  Now in this scenario I am using it assumes that StatusCode is storing “Closed” as text and not as the corresponding picklistid, which is not the standard OOTB SalesLogix behavior, but it should never the less demonstrate how to use the Not method to exclude a condition from your query result.


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!