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 = (Sage.Entity.Interfaces.IAccount)this.GetParentEntity();
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 = Sage.Platform.Application.ApplicationContext.Current.Services.Get<IEntityHistoryService>(); // 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)); } }




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