RuleSession
Functions for creating entities and executing rules. Should always be created via inrule.createRuleSession()
createEntity(entityName, boundValue)
Returns: Entity
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
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
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
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.
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
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;