Entity functions - hdijkema/espocrm-hookedformulas GitHub Wiki

Introduction

These functions relate to complete entities. Although very convenient to use, they will generally be much slower than the record* equivalents. For more information on the EspoCRM record functions these functions are derived from, see here.

See also the Attr and the SetAttr functions in the main section.

Entity\Get

ENTITY = Entity\Get(ENTITY-TYPE, ID)

Returns the entity of type 'entity-type' for the given id, or null if non existent.

Example:

$account_id = account.id;
$account = Entity\Get('Account', $account_id);
setAttr($account, 'lastRead', datetime\now());
logAdd(log, 'info', 'Account: ', attr($account, 'name'));
entity\save($account);

Entity\Save

Entity\Save(ENTITY)

Saves the given entity to the database. Example, see above.

Entity\This

ENTITY = Entity\This()

Returns the current entity for the given formula as a variable.

Example for a formula on entitytype Contact:

$e = entity\this();
$name = attr($e, 'name');

Entity\GetMany

LIST-OF-ENTITY = Entity\GetMany(ENTITY-TYPE, LIMIT, [ORDER_BY, ORDER, KEY1, VALUE1, KEY2, VALUE2 ...])

Example:

$entities = Entity\GetMany('Contact', 100, 'lastName', 'asc', 'code!=', '99');
$n = array\length($entities);
$i = 0;
while($i < $n,
  $c = array\at($entities, $i);
  logAdd(log, 'info', 'contact - ', attr($c, 'name'));
  $i = $i + 1;
);

Entity\GetRelated

LIST-OF-ENTITY = Entity\GetRelated(ENTITY, LINK, LIMIT, [ORDER_BY, ORDER, KEY1, VALUE1, KEY2, VALUE2 ...])

Example:

logAdd(log, 'info', 'Contact ', name, ' has following stores');
$stores = Entity\GetRelated(Entity\this(), 'accounts', 10000, 'lastName', 'asc', 'accountType=', 'store');
$n = array\length($stores);
$i = 0;
while($i < $n,
  $store = array\at($stores, $i);
  logAdd(log, 'info', 'Store - ', attr($store, 'name'));
  $i = $i + 1;
);
⚠️ **GitHub.com Fallback** ⚠️