Let’s say we have a new entity called widgets. These widgets can be tied to contacts and/or accounts.
The widgets have a few fields price, quantity, date, and color.
The widgets have a relationship to contacts and accounts too.
You can add widgets from the contact’s mainview and from the account’s mainview since there is a more tab (quickform) for each. To add a widget you press the little green plus and the addeditwidget quickform appears.
This addeditwidget quickform is found in AA under the widget entity (not under contact or account).
When you press add widget from a contact (say John Abbott) you want John Abbot and Abbott ltd. to show on the insert widget form that shows as a dialog right?
In order to do this you need to set the widget.contact and widget.account.
Well you need to know that when that dialog “pops up” you can insert some code.
C# code specifically. You can tell the current entity in a load action of the form by typing:
Sage.Entity.Interfaces.IWidget widget = this.BindingSource.Current as Sage.Entity.Interfaces.IWidget;
Now you can get the parent of that widget by saying:
this.GetParentEntity();
But this addeditwidget form is loaded from both the contact and account. What if you have a contact? What if it is an account? You can set both the contact and account if the parent is a contact. You can only set the account if the parent is an account.
So you check:
object parent = this.GetParentEntity();
if(parent is Sage.Entity.Interfaces.IAccount)
{
//we have an account, set the account
widget.Account = (Sage.Entity.Interfaces.IAccount)parent;
//assuming the widget has a relationship called Account
}
else if(parent is Sage.Entity.Interfaces.IContact)
{
//we have a Contact, set the account and contact
Sage.Entity.Interfaces.IContact contact = (Sage.Entity.Interfaces.IContact)parent;
widget.Account = contact.Account;
widget.Contact = contact;
//assuming the widget has a relationship called Account and one called Contact
}
else
{
//well this is an awkward else isn't it?
}
The context for each control will be set for you. Enjoy!










