Record functions - hdijkema/espocrm-hookedformulas GitHub Wiki
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
- Record\FindMany
- Record\FetchMany
- Record\FetchManyHash
- Record\FetchRelatedMany
- Record\FetchRelatedManyHash
- Record\CountRel
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);
ID_LIST = Record\FindMany(ENTITY_TYPE, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])
Note:
- CONDITION_KEY == 'limit by', VALUE = MAX_RECORDS will limit the results to MAX_RECORDS.
- CONDITION_KEY == 'use filter', VALUE = FILTER will use the given filter instead of condition keys, see Record\FindRelatedMany documentation of EspoCRM for FILTER.
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);
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:
- CONDITION_KEY == 'limit by', VALUE = MAX_RECORDS will limit the results to MAX_RECORDS.
- CONDITION_KEY == 'use filter', VALUE = FILTER will use the given filter instead of condition keys, see Record\FindRelatedMany documentation of EspoCRM for FILTER.
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;
);
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:
- CONDITION_KEY == 'limit by', VALUE = MAX_RECORDS will limit the results to MAX_RECORDS.
- CONDITION_KEY == 'use filter', VALUE = FILTER will use the given filter instead of condition keys, see Record\FindRelatedMany documentation of EspoCRM for FILTER.
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;
);
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:
- CONDITION_KEY == 'limit by', VALUE = MAX_RECORDS will limit the results to MAX_RECORDS.
- CONDITION_KEY == 'use filter', VALUE = FILTER will use the given filter instead of condition keys, see Record\FindRelatedMany documentation of EspoCRM for FILTER.
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;
);
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:
- CONDITION_KEY == 'limit by', VALUE = MAX_RECORDS will limit the results to MAX_RECORDS.
- CONDITION_KEY == 'use filter', VALUE = FILTER will use the given filter instead of condition keys, see Record\FindRelatedMany documentation of EspoCRM for FILTER.
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;
);
COUNT = Record\CountRel(ENTITY_TYPE, ID, LINK, ATTRIBUTES_TO_FETCH, ORDER_BY, ORDER, [CONDITION_KEY1, VALUE1, ...])
Returns the number of related records.