Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Nickel Contributor
Posts: 93
Registered: ‎01-02-2010
Accepted Solution

Access parent attributes while on an 'Add' form

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

Silver Contributor
Posts: 764
Registered: ‎04-17-2009

Re: Access parent attributes while on an 'Add' form

Try (IAccount)GetParentEntity()... This works as long as you are invoking the add dialog using the regular "Insert Child" options.

 

Bronze Super Contributor
Posts: 236
Registered: ‎03-30-2009

Re: Access parent attributes while on an 'Add' form

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;
                            }
                        }
                    }
                }

 

 

Mike LaSpina
Professional Services Consultant

Sage
8800 N Gainey Center Dr Ste 200
Scottsdale AZ 85258
Tel: 480-383-5344
Cell: 480-321-6637
Fax: 480-556-4090
mike.laspina@sage.com

Your Business in Mind.
Nickel Contributor
Posts: 93
Registered: ‎01-02-2010

Re: Access parent attributes while on an 'Add' form

Mike, this is just what I needed, thank you very much for posting the code.

 

Phil