Using the EntityHistoryService to Retrieve Previously Accessed Entities

There are many ways to get the “current” account in SalesLogix Web. For those coming from developing for the SalesLogix Windows client, you’ll likely¬†want the same capabilities that the BasicFunctions CurrentAccountID provides. In the web platform, however, there is all of that, plus more.

If your QuickForm or SmartPart is a child of the Account entity, you can reference the parent account instance using GetParentEntity:

Sage.Entity.Interfaces.IAccount account =

If the parent of your SmartPart is an account (meaning your SmartPart is on an entity page for type IAccount), then that will get it for you just fine.

Another option, which is a bit more limited, is to get the parent account for the current entity instance. This will, of course, only work if your current entity instance has a parent account. For example, let’s say your on a Contact-level SmartPart and you want to get the parent account:

Sage.Entity.Interfaces.IContact contact =
    this.BindingSource.Current as Sage.Entity.Interfaces.IContact;

if (contact != null)
    Sage.Entity.Interfaces.IAccount account = contact.Account;

This works great if you have a parent account for the current entity instance. Let’s say that you create an entirely new area for the client and you’d like to default the account to the current account (or really the last account the user visited) when creating new instances of your entity. The Sage Platform provides an Entity History Service for just this purpose. In the sample code below let’s grab a reference to the last account visited:

// First access the EntityHistory service
Sage.Platform.Application.IEntityHistoryService entityHistoryService =

// Now let's use it to get the ID of the last Account accessed
string accountId = entityHistoryService.GetLastIdForType<IAccount>().ToString();

// And get a reference to the entity
IAccount account = Sage.Platform.EntityFactory.GetById<IAccount>(accountId);

You can also use that service to to back much further, beyond just the last entity accessed, but all the past ones accessed. Let’s say you want to get a list of all previously accessed accounts:

List<string> accountlist = new List<string>();
foreach (EntityHistory entity in entityHistoryService)
    if (entity.EntityType == typeof(IAccount))
        accountlist.Add(string.Format("Accessed {0} ({1})", entity.Description, entity.EntityId));

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of 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.

1 Comment

  1. I can see this working in my current project. Thanks Ryan.


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!