Field

  • Updated

Runtime representation of a Field.

getName() Returns: string

Description:

Returns a string of the Field's name

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1");
var field = entity.getField("Field1"); var fieldName = field.getName(); // fieldName 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 field = entity.getField("Field1"); var fieldId = field.getElementId(); // fieldId is "Entity1:1/Field1";

 

getValue() Returns: object

Description:

Returns the Field's value

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"

 

setValue(value) Returns: void

Parameters:

value

Type: object

The value you want to set the Field to. If the type of the value does not match the type

of the Field, implicit conversion will take be attempted.

Description:

Sets the Field's value

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"

 

getField(fieldName) Returns: Field

Parameters:

fieldName

Type: string

The name of the Field to return

Description:

For Entity and Complex fields, returns a child Field from the Field instance

Code Sample:

var session = inrule.createRuleSession();
// Assume Person has a field "FirstName" and a 
field "Child" that is of type "Person" var boundValue = // A method that returns a person, its child and grandchild var entity = session.createEntity("Person", boundValue);
var child = entity.getField("Child"); var grandchild = child.getField("Child");

 

getCollection(collection Name) Returns: Collection

Parameters:

collectionName

Type: string

The name of the Collection to return

Description:

For Entity and Complex fields, returns a child Collection from the Field instance

Code Sample:

var session = inrule.createRuleSession();
// Assume Person has a Field "FirstName" and 
a Collection "Children" that is of type "Person" var boundValue = // A method that returns a person, its children var entity = session.createEntity("Person", boundValue);
var children = entity.getCollection("Children");

 

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 "Field1"
as Invalid session.applyRules(function(log){ // entity1.getField("Field1").isValid() returns False });

 

metadata Returns: AuthoringMetadata

Description:

This returns an AuthoringMetadata object for the Field

Code Sample:

var session = inrule.createRuleSession(); 
var entity = session.createEntity("Entity1");
var field = entity.getField("Field1"); var displayName = field.metadata.displayName;

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.