Record functions - hdijkema/espocrm-hookedformulas GitHub Wiki

Introduction

These functions work on records and are convenient when one wants to create e.g. reports. Because they work directly with records, they are quite fast.

Record\Recalculate

BOOL = Record\Recalculate(ENTITY_TYPE, [CONDITION_KEY1, VALUE1, ...])

Triggers recalculation of the records of ENTITY_TYPE that satisfy the conditions. It does this by setting the 'modifiedAt' attribute of the record and saving the record, which will trigger the 'beforeSave' and the 'afterSave' hooks of the ENTITY_TYPE, thus making it recalculate.

Returns false if something went wrong.

Example

Record\Recalculate('RelatedTotals', 'year=', 2020);

Record\FindMany

ID_LIST = Record\FindMany(ENTITY_TYPE, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

Note:

Finds the record ids for the given ENTITY_TYPE, ordered by the given order. Returns a list of ids.

Example

$ids = Record\FindMany('Store', 'name', 'asc', 'code=', '30', 'limit by', 10);

Record\FetchMany

ARRAY OF ROW = Record\FetchMany(ENTITY_TYPE, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

ROW is an ARRAY of Attributes, as represented by ATTRIBUTES_TO_FETCH.

Note:

Returns an array of rows. See also the more convenient function Record\FetchManyHash.

Example:

$dt = datetime\yearAdd(datetime\now(), -1);
$rows = record\fetchmany('Store', 'id, name, code', 'name', 'asc', 'lastMailed<', $dt);
$n = array\length($rows);
$i = 0;
while($i < $n,
  $row = array\at($rows, $i);
  logAdd(log, 'store: ', array\at($row, 1), ' - code: ', array\at($row, 2));
  $i = $i +1;
);

Record\FetchManyHash

ARRAY OF HASHROW = Record\FetchManyHash(ENTITY_TYPE, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

HASHROW is a HASH of Attributes, as represented by ATTRIBUTES_TO_FETCH.

Note:

Returns an array of rows.

Example:

$dt = datetime\yearAdd(datetime\now(), -1);
$rows = record\fetchManyHash('Store', 'id, name, code', 'name', 'asc', 'lastMailed<', $dt);
$n = array\length($rows);
$i = 0;
while($i < $n,
  $row = array\at($rows, $i);
  logAdd(log, 'store: ', hash\get($row, 'name'), ' - code: ', hash\get($row, 'code'));
  $i = $i +1;
);

Record\FetchRelatedMany

ARRAY OF ROW = Record\FetchRelatedMany(ENTITY_TYPE, ID, LINK, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

ROW is an ARRAY of Attributes, as represented by ATTRIBUTES_TO_FETCH.

Note:

Returns an array of rows. See also the more convenient function Record\FetchRelatedManyHash.

Example:

$rows = record\fetchrelatedmany('Contact', id, 'stores', 'id, name, code', 'name', 'asc', 'code=', '33');
$n = array\length($rows);
$i = 0;
while($i < $n,
  $row = array\at($rows, $i);
  logAdd(log, 'stores for contact with code 33: ', array\at($row, 1), ' - code: ', array\at($row, 2));
  $i = $i +1;
);

Record\FetchRelatedManyHash

ARRAY OF HASHROW = Record\FetchRelatedManyHash(ENTITY_TYPE, ID, LINK, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

HASHROW is an HASH of Attributes, as represented by ATTRIBUTES_TO_FETCH.

Note:

Returns an array of rows has associative arrays (hashes).

Example:

$rows = record\fetchrelatedmanyhash('Contact', id, 'stores', 'id, name, code', 'name', 'asc', 'code=', '33');
$n = array\length($rows);
$i = 0;
while($i < $n,
  $row = array\at($rows, $i);
  logAdd(log, 'stores for contact with code 33: ', hash\get($row, 'name'), ' - code: ', hash\get($row, 'code'));
  $i = $i +1;
);

Record\CountRel

COUNT = Record\CountRel(ENTITY_TYPE, ID, LINK, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])

Returns the number of related records.

⚠️ **GitHub.com Fallback** ⚠️