Skip to main content



Working with Rule Application Metadata

Using the RuleApplicationDef Object​

Prerequisites​

A valid RuleSession

Namespaces​

InRule.Runtime

See Also​

Creating a RuleSession


RuleApplicationDef metadata​

// System and user-defined attributes 
string attributeValue = ruleSession.GetRuleApplicationDef().Attributes["MyAttribute"];

// Categories defined in the rule application
CategoryDefCollection categories = ruleSession.GetRuleApplicationDef().Categories;

// Getting name of first category in collection
string catalogName = categories[0].Name;

// Getting DataElementDef
DataElementDef dataElementDef = (DataElementDef)ruleSession.GetRuleApplicationDef().DataElements["MyInlineTable"];

Iterate through the entities of a rule application​

// Iterate through the entities for the rule application 
foreach (EntityDef entityDef in ruleSession.GetRuleApplicationDef().Entities){
Console.WriteLine(entityDef.Name);
}

Retrieving Definition Objects at Runtime​

Prerequisites​

A valid RuleSession

Namespaces​

InRule.Runtime , InRule.Repository , InRule.Repository.RuleElements

See Also​

Using Element Metadata

The following examples demonstrate how to retrieve definition objects through the runtime objects. These objects can then be utilized to access object metadata and user-defined attributes.

// Get EntityDef from EntityEntityDef
entityDef = entity.GetDef();
// Get FieldDef from FieldFieldDef
fieldDef = field.GetDef();
// Get CollectionDef from Collection, assigned to FieldDef 
FieldDef collectionDef = collection.GetDef();
// Get RuleSetDef from RuleSet 
RuleSetDef ruleSetDef = (RuleSetDef)ruleSet.GetDef();
// Get RuleElementDef from RuleElement, getting first child element in this example 
RuleElementDef ruleElementDef = ruleSet.RuleElements[0].GetDef();

Using Element Metadata​

Prerequisites​

A valid RuleSession

Namespaces​

InRule.Runtime , InRule.Repository , InRule.Repository.RuleElements

See Also​

Retrieving Definition Objects at Runtime

The definition objects, available at runtime, can be used to retrieve element definitions and user-defined metadata. See Retrieving Definition Objects at Runtime for details.

Iterate through the fields objects on an entity​

// Iterate through fields in an entity 
foreach (FieldDef fieldDef in invoiceEntity.GetDef().Fields)
{if (fieldDef.IsCalculated) // Display the expression if a calculation
Console.WriteLine(fieldDef.Calc.FormulaText);

if (fieldDef.IsAnEntityDataType) // Display the referenced entity if a child entity field
Console.WriteLine(fieldDef.DataTypeEntityName);
}

Field metadata​

// Get data type 
string dataType = fieldDef.DataType.ToString();

// Get default value
string defaultValue = fieldDef.DefaultValue.ToString();

// Get Attributes
ICollection attributes = fieldDef.Attributes.Values;

// Get assigned categories
ICollection assigned = fieldDef.AssignedCategories;

Iterate through the rulesets on an entity​

// Iterate through the rule sets on an entity 
foreach (RuleSet ruleSet in invoiceEntity.RuleSets){
// Cast into a RuleSetDef
RuleSetDef ruleSetDef = (RuleSetDef)ruleSet.GetDef();
// See if this is an active explicit ruleset
if (ruleSetDef.FireMode == RuleSetFireMode.Explicit && ruleSetDef.IsActive)
{ Console.WriteLine(ruleSet.Name);
}}

Working with Attributes​

Prerequisites​

A valid EntityDef and FieldDef

Namespaces​

InRule.Repository

See Also​

Creating a RuleSession, Retrieving Definition Objects at Runtime


Retrieve a user-defined attribute on an entity​

// Retrieve an attribute defined on an entity 
Console.WriteLine(entityDef.Attributes.Default["MyAttribute"];);

Iterate through the attributes on a field​

if (fieldDef.Attributes != null && fieldDef.Attributes.Count > 0){ 
foreach (XmlSerializableStringDictionary.XmlSerializableStringDictionaryItem attributeItemin fieldDef.Attributes.Default) { Console.WriteLine(attributeItem.Key + ":" + attributeItem.Value); }}

Working with Value Lists​

Prerequisites​

A valid Entity and RuleSession

Namespaces​

InRule.Runtime , InRule.Repository

Populating a combobox from a value list​

// Retrieve a value list that is associated to a field 
ValueList valueList = entity.Fields["State"];.AssociatedValueList;

foreach (ValueListItem valueListItem in valueList){
// Add the list item value to the combobox
comboBox.Items.Add(valueListItem); comboBox.DisplayMemberPath = "Value";
}

Populating a combobox from a standalone value list​

// Get value list using the session's DataManager 
ValueList myList = ruleSession.Data.GetValueList("StandAloneValueList");

// Tell combo box what field to display to the end user
comboBox.DisplayMemberPath = "DisplayText";

// Add the item to the combo box
foreach (ValueListItem item in myList){
comboBox.Items.Add(item); }