Insert into attribute value

Syntax

$object.add(`$attr`, $value)

$object.add(`$attr`, $index, $value)

Description

Appends a value to a set attribute attr of an object.

Can also be done with the set() function by concatinating the old set of attributes with the new value:

$object.set(`$attr`, concat(object.get(`$attr`).subList(0, $index), $value, object.get(`$attr`).subList($index)))

Parameter

Name Type Description Mandatory Default
object Business object The object to which a new value in an attribute should be added. yes
attr String The attribute literal of the attribute to which a value is to be added. The attribute must be a set. Attributes with only single values will generate an error message, since nothing can be added, only set (cf. Set attribute value). yes
index number The position in the set attribute where the new value is to be inserted. no

index = object.get(`$attr`).size()

In this case the new value will be inserted at the end of the set.

value Number/string/boolean/business object/set The new value to add to the object's attribute. yes

Examples

Insert new child

	{
   parent = new(`my.module:MyType`);
   child = new(`my.module:MyType`);
   $parent.add(`my.module:MyType#children`, $child);
   $parent.get(`my.module:MyType#children`);
}

Output: A set with the element [child].

After two objects have been created, one object has been added to the other as a child.

Insert new child at index

	{
   parent = new(`my.module:MyType`);
   child1 = new(`my.module:MyType`);
   child2 = new(`my.module:MyType`);
   child3 = new(`my.module:MyType`);
   $parent.add(`my.module:MyType#children`, $child1);
   $parent.add(`my.module:MyType#children`, $child3);
   $parent.add(`my.module:MyType#children`, 1, $child2);
   $parent.get(`my.module:MyType#children`);
}

Output: A set with the elements [child1, child2, child3].

The object child2 is inserted by specifying the index between child1 and child3.