AddRefAttribute(Attribute: IRdsAttribute; RefAttribute: IRdsAttribute; Ascending: Boolean): IRdsSortAttribute;
Attribute. Sorting attribute.
RefAttribute. Reference sorting attribute.
Ascending. Direction of sorting.
The AddRefAttribute method adds sorting for attributes that take part in the connections and enables the user to set attribute from another dictionary for sorting by its values.
Available values of the Ascending parameter:
True. Ascending sorting.
False. Descending sorting.
Executing the example requires an MDM repository with the MDM_SORT identifier. This repository contains MDM dictionaries with the SORT and COUNTRY identifiers. The SORT dictionary contains the LINK_COUNTRY attribute that refers to COUNTRY.
Add links to the Metabase, Rds system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
RdsKey: Integer;
DictObj: IMetabaseObjectDescriptor;
DictInst: IRdsDictionaryInstance;
Sorter: IRdsElementsSorter;
Elems: IRdsDictionaryElements;
Attrs: IRdsAttributes;
Attr, RefAttr: IRdsAttribute;
Begin
Mb := MetabaseClass.Active;
// Get key of the MDM repository
RdsKey := Mb.ItemById("MDM_SORT").Key;
// Get MDM dictionary to be sorted
DictObj := Mb.ItemByIdNamespace("SORT", RdsKey);
DictInst := DictObj.Open(Null) As IRdsDictionaryInstance;
// Get sorted elements
Elems := DictInst.Elements;
// Create the object that sorts elements
Sorter := Elems.CreateSorter(Elems.Root);
// Get attributes of the sorted dictionary
Attrs := DictInst.Dictionary.Attributes;
// Get the attribute used in the link
Attr := Attrs.FindById("LINK_COUNTRY");
// Get associated dictionary
DictObj := Mb.ItemByIdNamespace("COUNTRY", RdsKey);
DictInst := DictObj.Open(Null) As IRdsDictionaryInstance;
// Get attributes of associated dictionary
Attrs := DictInst.Dictionary.Attributes;
// Get attribute by whose values the items will be sorted
RefAttr := Attrs.FindById("NAME");
// Set sorting attribute
Sorter.Attributes.AddRefAttribute(Attr, RefAttr, True);
// Sort items and save results
Sorter.Sort(True);
Sorter.Save;
End Sub UserProc;
Example execution result: elements of the SORT dictionary are sorted in ascending order by values of the NAME attribute contained in the linked dictionary.
See also: