RuleSession

  • Updated

Functions for creating entities and executing rules. Should always be created via inrule.createRuleSession()

createEntity(entityName, boundValue) Returns: Entity

Parameters:

entityName

Type: string

The name of the Entity to create

boundValue

Type: object

An optional JavaScript object that contains data that the Entity will be bound to, if null an empty object is bound.

Description:

Creates and returns an Entity of the specified name and bound to the provided value

Code Sample:

var session = inrule.createRuleSession(); 
var boundValue = { "FirstName" : "John" }; var entity = session.createEntity("Entity1", boundValue);

 

executeIndependentRuleSet(ruleSetName, arguments, callback) Returns: void

Parameters:

ruleSetName

Type: string

The name of the RuleSet to create

arguments

Type: Array of objects

An Array of values to pass to the RuleSet. The values are bound to the arguments by ordinal positioning. If an argument is Entity, the value passed to it will be used as the Entity's bound value. If the RuleSet does not have parameters, pass an empty array.

callback

Type: function(log)

A JavaScript function accepting a RuleExecutionLog object as its parameter

Description:

Executes the Independent Rule Set with the specified name. If arguments are provided they are passed to the Independent Rule Set.

Code Sample:

var session = inrule.createRuleSession(); 
session.executeIndependentRuleSet("RuleSet1", [1, "value"],
function(log){ // Code that checks the Execution Log });

 

createIndependentRuleSet(ruleSetName) Returns: RuleSet

Parameters:

ruleSetName

Type: string

The name of the RuleSet to create

Description:

Creates and returns a RuleSet

Code Sample:

var session = inrule.createRuleSession();
var ruleSet = session.createIndependentRuleSet("RuleSet1");

 

getEntities() Returns: Array of Entity objects

Description:

Returns a JavaScript Array of Entity objects created explicitly via createEntity() or during the execution of rules in the current RuleSession

Code Sample:

var session = inrule.createRuleSession(); 
session.createEntity("Entity1"); var entities = session.getEntities(); var entityCount = entities.length; // entityCount is now 1

 

applyRules(callback) Returns: void

Parameters:

callback

Type: function(log)

A JavaScript function accepting a RuleExecutionLog object as its parameter

Description:

Applies all Auto Single-Pass Sequential Rule Sets and evaluates all Calculated Fields against all Entities in the current RuleSession. The callback provided is invoked upon completion of rule execution.

If an error occurs during rule exection, the hasErrors property on the RuleExecutionLog will return True. Error details can be accessed via the runtimeErrors Array.

Code Sample:

var session = inrule.createRuleSession(); 
session.createEntity("Entity1");
session.applyRules(function(log){ // Code that checks the Execution Log });

 

getActiveNotifications() Returns: Array of Notification objects

Description:

Returns an Array of Notifications from the last rule execution

Code Sample:

var session = inrule.createRuleSession(); 
session.createEntity("Entity1");
// Assuming Entity1 has a Rule Set that fires 1 Notification session.applyRules(function(log){ var notifications = session.getActiveNotifications(); var notificationCount = notifications.length; // notificationCount is now 1 });

 

getActiveValidations() Returns: Array of Validation objects

Description:

Returns an Array of Validations from the last rule execution

Code Sample:

var session = inrule.createRuleSession(); 
session.createEntity("Entity1");
// Assuming Entity1 has a Rule Set that sets 1 Field invalid session.applyRules(function(log){ var validations = session.getActiveValidations(); var validationCount = validations.length; // validationCount is now 1 });

 

setNow(date) Returns: void

Parameters:

date

Type: Date

A Date object representing the date/time used for the Today() and Now() syntax functions

Description:

Sets the value of the date/time to use for the Today() and Now() syntax functions during rule execution. If not set, new Date() will be used when rules execute.

Code Sample:

var session = inrule.createRuleSession(); 
session.setNow(new Date(1995, 5, 1);

 

executionLog Returns: RuleExecutionLog

Description:

Returns a RuleExecutionLog of the last rule execution

Code Sample:

var session = inrule.createRuleSession(); 
session.createEntity("Entity1");
session.applyRules(function(log){ // The parameter log is a reference to session.executionLog });

 

dataManager Returns: DataManager

Description:

Returns a DataManager object that is used to get Value Lists and Inline Tables

Code Sample:

var session = inrule.createRuleSession();
var myTable = session.dataManager.getInlineTable("MyTable");

 

metadata Returns: AuthoringMetadata

Description:

Returns an AuthoringMetadata object for the Rule Application

Code Sample:

var session = inrule.createRuleSession();
var displayName = session.metadata.displayName;

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.