Using Element Metadata

  • Updated

Prerequisites: A valid RuleSession
Namespaces: InRule.Runtime, InRule.Repository, InRule.Repository.RuleElements
Classes: EntityDef, FieldDef, RuleSetDef, RuleElement
See Also: Retrieving Definition Objects at Runtime

Element definition and user-defined metadata can be retrieved from the definition objects, which are available at runtime.  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);
   }
}

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.