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?
Thanks
Phil
Solved! Go to Solution.
12-01-2010 01:13 PM
Try (IAccount)GetParentEntity()... This works as long as you are invoking the add dialog using the regular "Insert Child" options.
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)
{
string str;
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;
break;
}
}
}
}
12-03-2010 04:47 AM
Mike, this is just what I needed, thank you very much for posting the code.
Phil