MbElementDependentTemplateClass.CreateByElement

Syntax

CreateByElement(DictionaryKey: Integer; ElementKey: Integer);

Parameters

DictionaryKey. MDM dictionary key.

ElementKey. MDM dictionary element key.

Description

The CreateByElement constructor creates a new dependencies template in accordance with specified object parameters of MDM dictionary and dictionary element.

Comments

To get object keys and a dictionary, use the IMetabaseObjectDescriptor.Key property or the IMetabase.GetObjectKeyById method. To get an element key, use the IRdsDictionaryElement.Key property, or the IRdsDictionaryElements.Element property.

Example

Executing the example requires MDM dictionaries with the DICT and DICT1 identifiers.

Add links to the Metabase, Rds system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Obj, Dictionary: IMetabaseObjectDescriptor;
    Elements: IRdsDictionaryElements;
    Depends: IMbElementDependents;
    Template: IMbElementDependentTemplate;
Begin
    MB := MetabaseClass.Active;
    Dictionary := MB.ItemById(
"Dict_1");
    Obj := MB.ItemById(
"Obj_1");
    Elements := (Dictionary.Open(
NullAs IRdsDictionaryInstance).Elements;
    
// Object settings:
    Dictionary := Dictionary.EditDescriptor;
    Dictionary.ElementDependenciesTrackingType := MbElementDependenciesTrackingType.Dependents;
    Dictionary.SaveDescriptor;
    
// New template for adding a dependency
    // Template is created for the first MDM dictionary element
    Template := New MbElementDependentTemplateClass.CreateByElement(Dictionary.Key, Elements.Element(1));
    Template.ObjectKey := Obj.Key;
    
// Collection of elements dependencies
    Depends := Dictionary.ElementDependents;
    Depends.Add(Template);
    Depends.Database.Update(Depends);
    Debug.WriteLine(
"Number of records of MDM dictionary elements dependency on objects: " + Depends.Count.ToString);
End Sub UserProc;

After executing the example a function of monitoring dependencies of dictionary elements on repository objects is enabled for the specified dictionary. A new dependency from the specified object will be created or the first element. The list of dependencies will be saved in the repository database.

See also:

MbElementDependentTemplateClass