Formula recordURL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tinchux
    Junior Member
    • Dec 2021
    • 12

    Formula recordURL

    Hi! I need some help with formula. How can I get de recordURL from the entity Case before save?. I wourld like to print a URL reference from a case record and send it by Email. I can send Email ok

    thanks in advance
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1602

    #2
    I use this code:

    Create custom\Espo\Custom\Resources\metadata\app\formula. json

    Code:
    { "functionList": [ "__APPEND__", { "name": "string\\getSiteUrl", "insertText": "string\\getSiteUrl()" } ], "functionClassNameMap": { "string\\getSiteUrl": "Espo\\Custom\\Core\\Formula\\Functions\\Strin gGro up\\GetSiteUrl" } }
    Create custom\Espo\Custom\Core\Formula\Functions\Base\Str ingGroup\GetSiteUrl.php (the modification is in the path, green folder name, add it also to the namespace!)


    Code:
    <?php
    
    namespace Espo\Custom\Core\Formula\Functions\Base\StringGrou p;
    
    use Espo\Core\Utils\{
    Config,
    Config\ConfigFileManager
    };
    
    class GetSiteUrl extends \Espo\Core\Formula\Functions\Base {
    
    public function process(\StdClass $args = null) {
    $fileManager = new ConfigFileManager();
    $config = new Config($fileManager);
    return $config->getSiteUrl();
    }
    
    }

    Clear cache (probably also Browser cache). This will read https://yourHostname.domain and the function string\getSiteUrl() will appear in the function list of the formula.

    To get the entire URL you will have to concatenate the necessary parts of the URL by formula and output in another field, like so (an example to get a complete link to an image embedded in your entity):

    Field 1: current URL (Text), where you fetch the current hostname:


    Code:
    currentURL=string\getSiteUrl();
    Additional Code to get an image URL

    Field 2: concatenate currentURL with image link:


    Code:
    imageAddress=string\concatenate(
    currentURL, '/','?entryPoint=DubasPublicAttachment&id='
    );
    What happens here:

    The formula takes the hostname from the previous created field, a slash is added and after that the entry point part. This part I get from the image link (copy any image link one time, to see, how it is formed). In my case I use for downloading images the free extension from emillod called DubasPublic Attachment, which allows downloads from outside of espoCRM (you can find it here: https://github.com/dubas-pro/ext-public-attachment). Mind the security isues in case of production sites.

    Field 3: complete URL in an URL field. Concatenate the above string with the file ID (or image ID) of the current record:


    Code:
    imageDownloadLink=string\concatenate(imageAddress, imageId);

    ​​

    Comment

    Working...