Skip to content

hdijkema/espocrm-hookedformulas

Repository files navigation

espocrm-hookedformulas

A module that creates more formula possibilities for EspoCRM

Introduction

This module for EspoCRM adds more sophisticated formula functionality to EspoCRM. Instead of only having formulas at the 'beforeSave' hook, this module will make it possible to implement formulas for other hooks.

The following hooks are supported:

  • afterSave
  • afterRelate
  • afterUnrelate
  • afterRemove
  • afterMassRelate

All hooks are called with the Entity the formula applies to. In addition, the following variables are provided in the formula for afterRelate and afterUnrelate:

  • $relationName - refers to the name of the relation that has been created on this Entity
  • $foreignId - refers to the id of the foreign entity that is provided by the relation
  • $foreignEntity - is the instantiated foreign Entity for $foreignId.

For afterMassRelate, following variables are provider:

  • $relationName - refers to the name of the relation that has been created on this Entity
  • $relationParams -

See EspoCRM Hooks for more information about the hooks.

Simple example

In your formula you create sections for the different hooks. The afterSave section is implicit, because EspoCRM already provides this in the formulas. It can however be made explicit. Below is a simple formula for a given 'Entity':

   begin:beforeSave
     name = string\concatenate(name, ' - before save');
   end:beforeSave
   
   begin:afterSave
     record\recalculate('OtherEntity', 'entityId=', 'id');
   end:afterSave
   
   begin:afterRelate
     $nrecs = record\attribute('Entity', id, 'RelatedRecs');
     $nrecs = $nrecs + 1;
     record\update('Entity', id, 'RelatedRecs', $nrecs); 
   end:afterRelate
   
   begin:afterUnrelate
     $nrecs = record\attribute('Entity', id, 'RelatedRecs');
     $nrecs = $nrecs - 1;
     record\update('Entity', id, 'RelatedRecs', $nrecs); 
   end:afterUnrelate

Provided functions

HookedFormulas provides a lot of new functions to be used in EspoCRM. For more information see the Functions section.

Developing

  1. Checkout espocrm-hookedformulas to ./HookedFormulas.
git clone https://github.com/hdijkema/espocrm-hookedformulas.git HookedFormulas
  1. Start coding.

Building the extension

  1. Increase version number specified in the VERSION file
  2. Run the build script
./build-hookedformulas.sh buildext
  1. You'll find a new zip file in the build directory

About

Module that creates more sophisticated formulas for EspoCRM

Resources

License

Stars

Watchers

Forks

Packages

No packages published