irScript provides APIs for interacting with the ambient execution context during rule processing. These methods and properties are accessible from the global ‘Context’ object:
var defName = Context.RuleElement.Name;
var parentEntityName = Context.Entity.Name;
var parentRuleSetName = Context.RuleSet.Name;
var categoryCount = Context.RuleApplication.Categories.Count;
Context has the following properties and methods:
Property Name | Data type | Read only? | Description |
RuleApplication | InRule.Repository.RuleApplic ationDef | Yes | Returns a copy of the currently- executing RuleApplicationDef instance |
RuleElement | RuleElement | Yes | Returns a CLR object that encapsulates details of the currently-executing rule element, or null if the currently-executing UDF is within a calculated field |
SchemaElement | Element | Yes | Returns a CLR object that encapsulates details of the currently-executing schema element (Entity or complex field or member), or null if the currently- executing UDF is within a calculated field |
Calc | Field | Yes | Returns a CLR object that encapsulates details of the currently-executing calculated field, or null if the currently- executing UDF is not within a calculated field |
Entity | Entity | Yes | Returns a CLR object that encapsulates details of the current context Entity, or null if the currently-executing UDF is within an independent ruleset |
RuleSet | RuleSet | Yes |
Returns a CLR object that encapsulates details of the current context ruleset, or null if the currently-executing UDF is within a calculated field |
ContextProperti es (see note) | System.IDictionary<string, object> | Yes | Returns a property bag useful for storing custom context state; contents are preserved for the lifetime of the ambient rule session |
GetEntity() | Entity | - |
Accepts an ElementIdentifier string parameter and returns that entity instance: var x = Context.GetEntity( ‘MyEntit y:1’ ); var val = x.Fields[ ‘Field1’ ].Value; |
GetElement() | Element | - |
Accepts an ElementIdentifier string parameter and returns that element instance: var x = Context.GetElement( ‘MyEnti ty:1/Field1’ ); var val = x.Value; GetElement() can resolve collections, fields, rulesets, or rules. |
FunctionLibrarie s | a dynamic collection of all external function libraries configured for the current RuleApplicationDef | Yes |
Provides dotted path access to configured .NET Assembly Function Libraries: var x = Context.FunctionLibraries.M yLib.MyFunc( 45 ); |
CreateEntity | Entity | - |
Provides for creation of new Entity instances: var x = Context.CreateEntity( ‘Cust omer’ ); var y = Context.CreateEntity( ‘Cust omer’, ‘MyNamespace.MyCustomerClas s, MyAssemblyName’ ); |
RemoveEntity | none | - |
Removes an Entity instance from the ambient session: Context.RemoveEntity( ‘Customer:3’ ); |
CreateIndepend entRuleSet | RuleSet | - |
Provides for creation of independent RuleSet instances: var x = Context.CreateIndependentRu leSet( ‘ValidationRules’ ); x.Execute(); |
GetNotifications | ScriptCollection | - |
Returns a collection of all (or optionally, only active) notifications in the ambient session: var activeNotes = Context.GetNotifications( t rue ); var allNotes = Context.GetNotifications( f alse ); |
GetValidations | ScriptCollection | - |
Returns a collection of all (or optionally, only active) validations for the ambient session: var activeValidations = Context.GetValidations( tru e ); var allValidations = Context.GetValidations( fal se ); |
ActivateRuleSet sByCategory | None | - |
Activates all rulesets for the specified category: Context.ActivateRuleSetsByC ategory( ‘validation’ ); |
DeactivateRuleS etsByCategory | None | - |
Deactivates all rulesets for the specified category: Context.DeactivateRuleSetsB yCategory( ‘validation’ ); |
ActivateRuleSet s | None | - |
Activates all rulesets identified by the given (non-instance-based) path: Context.ActivateRuleSets ( ‘/Entity1/RuleSet1’ ); |
DeactivateRuleS ets | None | - |
Deactivates all rulesets identified by the given (non-instance-based) path: Context.DeactivateRuleSets ( ‘/Entity1/RuleSet1’ ); |
GetEntities | ScriptCollection | - |
Returns a collection of all entity instances for the ambient session: var entities = Context.GetEntities(); |
* A special note regarding use of ContextProperties; these are intended to contain lightweight, user-defined objects and functions to be made available throughout a rule session lifetime. Adding runtime SDK objects like Entities, Fields, etc. to ContextProperties is not supported behavior and is likely to result in reduced performance or runtime errors.
Comments
0 comments
Please sign in to leave a comment.