Reference > Expressions > Built-in Functions > Control Functions > ForEachChild

ForEachChild

Iterates child object instances and computes a text value for each of them. These values are then optionally sorted, and then concatenated and separated by a specified delimiter.

Evaluates a text-valued expression for each related (child) object and concatenates the results into a single text value. The related objects are related to a single parent object via the childRelationshipRef parameter. The children can be ordered by specifying one or more sort fields of the child object as ordering keys.

Syntax

ForEachChild(parentObjectRef, recId, childRelationshipRef, childExpression, fieldAndOrder)

Enabled for

Search/Dashboard No
Business Rules Yes
Quick Actions Yes
Workflow Objects Yes
Reports No

Parameters

parentObjectRef

The parent business object as an object reference.

recId

RecID of the parent business object instance.

childRelationshipRef

The relationship that relates the parent to its children.

childExpression

An expression to evaluate for each child.

 

NOTE: If the final element of the concatenation is the same for each instance and is a literal value, the system interprets that literal value to be a delimiter. The system adds the delimiter to the end of every entry except for the last entry.

fieldAndOrder

(Optional) The order by which to sort the results. Each argument is a list of field names optionally followed by a space and ASC (ascending) or DESC (descending).  Ascending is the default. If you specify more than one sort order, they are applied in the order given.

 

This function can take an unlimited number of these parameters, including none.  Use additional instances of this parameter to sort the results even more.

Return Value

Text value.

Example

For example, to iterate all instances of the child business object called ResNoteHistory for a fixed issue with a certain RecID, use the following within the business rule of the parent business object:

ForEachChild("Issue_Fix", RecId, "ResNoteHistory#.", "LastModBy + '\t'
+ LastModDateTime
+ '\r\n' + ResolutionNote
+ '\r\n______________\r\n"', "CreatedDateTime ASC")

For each instance, the system concatenates the following information: the name of the person who last modified the instance (LastModBy), followed by a tab, followed by the date and time it was last modified (LastModDateTime), followed by a new line, and then the text of the resolution note (ResolutionNote), followed by a new line that contains an underline and followed by another new line. These concatenations are sorted by the date and time the instance was created (CreatedDateTime) in ascending (ASC) order.