Collection

  • Updated

Runtime representation of a collection. Accessed via Entity.getCollection(collectionName).

getName() Returns: string

Description:

Returns a string of the Collection's name

Code Sample:

var session = inrule.createRuleSession();
var entity = session.createEntity("Entity1");
var collection = entity.getCollection("Collection1");
var collectionName = collection.getName(); // collectionName is "Field1";

 

getElementId() Returns: string

Description:

The element identifier which uniquely identifies this Field within its RuleSession

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1");
var collection = entity.getCollection("Collection1");
var collectionId = collection.getElementId(); // collectionId is "Entity1:1/Collection1";

 

getCount() Returns: Number

Description:

Returns the number of elements in the Collection

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1"); var collection = entity.getCollection("Collection1"); var collectionCount = collection.getCount(); // collectionCount is 0

 

getValue() Returns: Object

Description:

Returns the Field's value

Code Sample:

var session = inrule.createRuleSession(); 
var boundValue = {"Collection1" : []}; var entity = session.createEntity("Entity1", boundValue);
var collection = entity.getCollection("Collection1"); var collectionValue = collection.getValue(); // collectionValue is the Array "Collection1" from boundValue

 

add(entity) Returns: CollectionMember

Parameters:

entity

Type: Entity

Optional value for the CollectionMember. If null, the CollectionMember that is added has no value.

Description:

Adds a new CollectionMember to the Collection and returns it

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1"); var collection = entity.getCollection("Collection1"); var collectionMember = collection.add();

 

getMember(zeroBasedM emberIndex) Returns: void

Parameters:

zeroBasedMemberIndex

Type: Number

The member index to return from the Collection

Description:

Returns a CollectionMember based on the index

Note: Even though collections have one based indexes in the engine, access via the SDK is zero based.

Code Sample:

var session = inrule.createRuleSession(); 
var boundValue = {"FirstName": "John"}; var entity = session.createEntity("Entity1", boundValue);
var field = entity.getField("FirstName"); var fieldValue = field.getValue(); // fieldValue is "John" field.setValue("Jane"); var fieldNewValue = field.getValue(); // fieldNewValue is "Jane"

 

metadata Returns: AuthoringMetadata

Description:

This returns an AuthoringMetadata object for the Collection

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1"); var collection = entity.getCollection("Collection1"); var displayName = collection.metadata.displayName;

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.