rbv_api.getRelatedRecordIds()

Purpose

Returns an array of related record IDs for the specified relationship field and object record ID.

Syntax

rbv_api.getRelatedRecordIds(objName,relFieldName,id)
				
			

Parameters

objName

Integration name of the object.

Throws an exception if the specified object integration name does not exist.

relFieldName

Integration name of the relationship field.

Throws an exception if the specified object integration name does not exist.

id

Record ID for which related records have to be fetched.

Throws an exception if the supplied ID does not resolve to a record in the specified object, or if the value is negative, zero, or otherwise invalid.

Return Value

Returns an array of IDs for records related through the specified relationship.

  • If related records exist, the array contains one or more record IDs.

  • If no related records exist, the method may return an empty array.

Example

Retrieve the IDs of records related through a specified relationship field.

var arr = rbv_api.getRelatedRecordIds("Room", "R1321", "{!id}");
for (var k = 0; k < arr.length; k++) {
var relatedId = arr[k];
rbv_api.println("id=" + relatedId);
}

Example: Handling Empty Results

The following example checks whether any related records were returned.

var arr = rbv_api.getRelatedRecordIds("Room", "R1321", "{!id}");
if (arr.length === 0) {
rbv_api.println("No related records found.");
}
else {
for (var k = 0; k < arr.length; k++) {
var relatedId = arr[k];
rbv_api.println("id=" + relatedId);
}
}

Example: Handling Exceptions

The following example demonstrates how to handle errors that may occur when the object name, relationship field name, or record ID is invalid.

try {
var arr = rbv_api.getRelatedRecordIds("Room", "R1321", "{!id}");
if (arr.length === 0) {
rbv_api.println("No related records found.");
}
}
catch (e) {
rbv_api.println("Unable to retrieve related records: " + e);
}