Skip to main content



Context

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 NameData typeRead only?Description
RuleApplicationInRule.Repository.RuleApplic ationDefYesReturns a copy of the currently- executing RuleApplicationDef instance
RuleElementRuleElementYesReturns a CLR object that encapsulates details of the currently-executing rule element, or null if the currently-executing UDF is within a calculated field
SchemaElementElementYesReturns 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
CalcFieldYesReturns 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
EntityEntityYesReturns a CLR object that encapsulates details of the current context Entity, or null if the currently-executing UDF is within an independent ruleset
RuleSetRuleSetYesReturns 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>YesReturns 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 sa dynamic collection of all external function libraries configured for the current RuleApplicationDefYesProvides dotted path access to configured .NET Assembly Function Libraries: var x = Context.FunctionLibraries.M yLib.MyFunc( 45 );
CreateEntityEntity-Provides for creation of new Entity instances: var x = Context.CreateEntity( 'Cust omer' ); var y = Context.CreateEntity( 'Cust omer', 'MyNamespace.MyCustomerClas s, MyAssemblyName' );
RemoveEntitynone-Removes an Entity instance from the ambient session: Context.RemoveEntity( 'Customer:3' );
CreateIndepend entRuleSetRuleSet-Provides for creation of independent RuleSet instances: var x = Context.CreateIndependentRu leSet( 'ValidationRules' ); x.Execute();
GetNotificationsScriptCollection-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 );
GetValidationsScriptCollection-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 sByCategoryNone-Activates all rulesets for the specified category: Context.ActivateRuleSetsByC ategory( 'validation' );
DeactivateRuleS etsByCategoryNone-Deactivates all rulesets for the specified category: Context.DeactivateRuleSetsB yCategory( 'validation' );
ActivateRuleSet sNone-Activates all rulesets identified by the given (non-instance-based) path: Context.ActivateRuleSets ( '/Entity1/RuleSet1' );
DeactivateRuleS etsNone-Deactivates all rulesets identified by the given (non-instance-based) path: Context.DeactivateRuleSets ( '/Entity1/RuleSet1' );
GetEntitiesScriptCollection-Returns a collection of all entity instances for the ambient session: var entities = Context.GetEntities();
note

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.