Entity
An instance of an authored Entity whose state is maintained by the RuleSession.
getField(fieldName)
Returns: Field
Description: Returns a Field object of the specified name
Code Sample:
var session = inrule.createRuleSession();
var entity1 = session.createEntity("Entity1");
var field = entity1.getField("Field1");
getCollection(collection Name)
Returns: Collection
Description: Returns a Collection of the specified name
Code Sample:
var session = inrule.createRuleSession();
var entity1 = session.createEntity("Entity1");
var field = entity1.getCollection("Collection1");
getValue()
Returns: object
Description: Returns the object bound to the current Entity
Code Sample:
var session = inrule.createRuleSession();
var boundValue = {"FirstName": "John"};
var entity = session.createEntity("Entity1", boundValue);
var entityValue = entity.getValue();
// entityValue and boundValue are identical
getName()
Returns: string
Description: Returns a string of the Entity's name
Code Sample:
var session = inrule.createRuleSession();
var entity = session.createEntity("Entity1");
var entityName = entity.getName(); // entityName is "Entity1";
getElementId()
Returns: string
Description: The element identifier which uniquely identifies this Entity within its RuleSession
Code Sample:
var session = inrule.createRuleSession();
var entity = session.createEntity("Entity1");
var entityId = entity.getElementId(); // entityId is now "Entity1:1"
isValid()
Returns: bool
Description: Returns a boolean indicating whether or not the current Entity is valid based on the rules that were executed. If rules have not been applied, this will always return True.
Code Sample:
var session = inrule.createRuleSession();
var entity1 = session.createEntity("Entity1");
// Assuming Entity1 has a Rule Set that marks it as Invalid
// entity1.isValid() returns True
session.applyRules(function(log){
// entity1.isValid() returns False
});
executeRuleSet(name, arguments, callback)
Returns: void
Description: Executes the Rule Set with the specified name on the Entity. If arguments are provided they are passed to the Rule Set.
Code Sample:
var session = inrule.createRuleSession();
var entity = session.createEntity("Entity1");
entity.executeRuleSet("RuleSet1", [1, "value"], function(log){
// Code that checks the Execution Log
});
metadata
Returns: AuthoringMetadata
Description: Returns an AuthoringMetadata object for the Rule Application
Code Sample:
var session = inrule.createRuleSession();
var entity = session.createEntity("Entity1");
var displayName = entity.metadata.displayName;