when you add a relation this is what you see:
the relation works perfectly but it is not best practice to leave it like this.
for full details look in the documentation: https://docs.microsoft.com/en-us/previous-versions/dynamics/ax-2012/reference/hh803130(v=ax.60)
as a quick guide here my notes:
Entity Relationship Diagram (ERD):
Cardinality defines the possible number of occurrences in one entity which is associated with the number of occurrences in another.
Example:
so this is how you will set it up:
RelatedCardinality
corresponds to the notation on the parent table (the one we where we set the relation, HcmBenfit)
[you have two options:
- Exactly one
use it when the field is mandatory yes
or when is assured unique by an index - ZeroOne
use it when the field is not mandatory
Cardinality
corresponds to the notation on the child table (the one we are referencing, HcmBenefitOption)
RelationshipType
the option you will commonly use are
- Association (is the basic one. you can always use it)
- Aggregation
- Composition
Aggregation use it only when
- The parent table has a delete action node that is defined to use this relation node.
- Any of the foreign key fields for this relation in the child table have their Mandatory property set to Yes.
Composition Is a stronger type of Aggregation. A table must not have more than one Composition relation. For example, a building is composed of rooms, and a given room cannot exist in more than one building.
Roles
you can leave the default
unless you need to use the same table related table in multiple relations.
see this post: https://community.dynamics.com/365/financeandoperations/b/axaptavsme/posts/use-one-table-for-creating-multiple-relation
Requirement: I need to use the single table to add
multiple relation on a table. For eg. I have a parent table Table1 with field
ItemId and ProcessItem. Now I need to add relation to InventTable to both
fields. Hence I have to create two relation with InventTable.
How
to do: Add two new relation in your table as shown
below.
‘
You
might get an error message after this,
'RelatedTableRole'
conflicts with another 'RelatedTableRole' on relation InventTable_Item on table
ProcessedItemTable.
Solution
to this error:
Set
below two properties to each relation
1.
UseDefaultRoleNames- set it to “NO”
2.
Role: Give any logical name here, for eg. “Item”
Now compile your table, error must
gone.
CreateNavigationPropertyMethods
The CreateNavigationPropertyMethods if this is set to
Yes, then Dynamics AX
will automatically create navigation methods for the related
table.
This method allows us to link two table buffer (parent and child) instances.
The value set in the RelatedTableRole property is used to define the name of the
navigation method.
If the UseDefaultRoleNames property is set to Yes (and the RelatedTableRole
property is blank), then the table names are effectively used as the navigation
methods.
In addition, the NavigationPropertyMethodNameOverride property can be
used to specify a navigation method name. This property is typically used if the
relatedTableRole is already a method or if the table name is too long.
It's important to note that the navigation methods are neither displayed in the
Methods node, nor are they visible under the table buffer methods displayed by
IntelliSense. They are similar to Map methods in the sense that the developer can
type them in and the compiler we know, despite the fact that the method name is
not available in the list of methods.
now I can do like this:
[SysClientCacheDataMethodAttribute(true)]
display Email email()
{
return this.HcmWorkerRelation().email();
}
No comments:
Post a Comment