10-20-2010 11:38 AM
I have a mental block.
Imagine a tab under Accounts which has an 'Add' button. After clicking the 'Add' button, the Add form is displayed for this one-to-many entity off Accounts..
How can I access the parent account at this point, in a code snippet (eg, retrieve the parent Account ID), before the record has been saved?
Solved! Go to Solution.
12-02-2010 01:53 PM
Typically, you will be creating the child from a parent screen anyway. In some cases, I like to put the following code into the OnCreate event to make sure the parent is populated (this assumes we're creating a child of opportunity):
Sage.Platform.Application.IEntityHistoryService svc = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Application.IEntityHistoryService>();
if (svc != null)
foreach (Sage.Platform.Application.EntityHistory history in svc)
if ((!string.IsNullOrEmpty(history.EntityId.ToString()) && (history.EntityId.ToString() != Sage.Platform.Orm.Entities.EntityViewMode.Insert.ToString())) && ((str = history.EntityType.Name.ToUpper()) != null))
if (str == "IOPPORTUNITY")
IOpportunity opp = Sage.Platform.EntityFactory.GetRepository<IOpportunity>().FindFirstByProperty("Id", history.EntityId);
MyEntity.Opportunity = opp;