Check;
The Check method checks if element values are unique by attributes included into the unique key.
Use the IRdsUniqueKey.Contains property to include an attribute to the unique key or to exclude it from the unique key.
If on editing or adding the unique key the uniqueness of the key is violated the exception is thrown. The user will see an error message.
Executing the example requires an MDM repository with the RDS_REPO identifier that contains an MDM dictionary with the RDS_DICT identifier.
Add links to the Metabase, Rds, Dal system assemblies.
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Dict: IRdsDictionary;
Attrs: IRdsAttributes;
Attr: IRdsAttribute;
UniqKeys: IRdsUniqueKeys;
UniqKey: IRdsUniqueKey;
Begin
MB := MetabaseClass.Active;
MObj := MB.ItemByIdNamespace("RDS_DICT", MB.ItemById("RDS_REPO").Key).Edit;
Dict := MObj As IRdsDictionary;
Attrs := Dict.Attributes;
UniqKeys := Dict.UniqueKeys;
// Determine identifier and attribute name
Attr := Attrs.Add;
Attr.DataType := DbDataType.String;
Attr.Id := "ATTRIBUTE";
Attr.Name := "State number";
// Create the unique key
UniqKey := UniqKeys.Add;
UniqKey.Name := "Unique key by state number";
UniqKey.Contains(Attr) := True;
// Check if elements' values are unique
UniqKey.Check;
// Save changes
(UniqKey.Dictionary As IMetabaseObject).Save;
End Sub UserProc;
After executing the example a custom attribute is created in the MDM dictionary. A unique key of MDM dictionary is created by this attribute.
See also: