One of the most useful annotations that you can set up on any of the attributes (elements) of the business entities in a data model is the foreign key filter.
Through this annotation, you can filter foreign keys by:
values extracted from the current record through using the standard XPath predicate of the relevant attribute,
complex expressions: literal and functions,
current record values and complex expressions.
Note that if the filter is not an XPath but a value, it needs to be enclosed in quotes (").
Before you begin
You have already created data models, business entities and attributes in the data model. For further information, see Creating a data model, Creating business entities in a data model and Adding attributes to the business entity.
About this task
Consider as an example that your data records hold the following entities: Agency, Agent and Region. The Agency and Region entities hold the Country attribute. In Talend MDM Web UI, you want to filter the foreign key values by the Country attribute.
To set a foreign key filter, do the following:
- Right-click the attribute to which you want to add the annotation, Agency > Region in this example.
In the contextual menu, select Set the Foreign Key
A dialog box displays.
- Click the icon to add a line to the table where you can define the foreign key filter.
- Click in the XPath column and then click the three-dot button to open a dialog box where you can select the XPath on which to set the foreign key filter.
Select Region > Country and then click
Add in the dialog box.
The XPath is set to Region/Country.
- Click in the Operator column and select an operator from the list, Contains in this example.
- Click in the Value column and then click the three-dot button to open a dialog box where you can select the value on which to set the foreign key filter.
Select Agency > Country and then click
Add in the dialog box.
The foreign key filter value is set to Agency/Country.Note: You can also use the function with the XPath predicate of a relevant attribute to set the foreign key filter value, for example, fn:abs(Product/Price). The XPath predicate of a String type attribute needs to be prepended with
xpath:, for example, fn:concat("xpath:Agency/Country","sample"). All supported functions can be found in the Expression area for setting a default value rule. For more information, see Setting a default value rule for an element.
If required, add multiple conditions and combine them using various
For more information, see Behaviors of filters using multiple conditions and predicates in Talend MDM.
In this example, you want to filter foreign keys based on the
Country attribute. Click OK to
close the dialog box.
The defined foreign key filter is displayed under the Annotation node of the Region element.
- Click the save icon on the toolbar or press Ctrl + S on your keyboard to save your modifications.
What to do next
Now in any agency record in Talend MDM Web UI, every time a user clicks on the foreign key icon next to the Region field, the list will only include the foreign keys based on the Country attribute.