Announcement

Collapse
No announcement yet.

Note on formula

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Note on formula

    Hallo,

    Missing in the list of functions
    number\floor & number\ceil functions
    lowerCase & upperCase functions

    peter

  • #2
    Hello
    Not all functions are in list, some of them you can find only in the documentation.

    Comment


    • #3
      We can't use these string on Print2PDF Template can we?

      Comment


    • #4
      Thanks Maximus

      I was more interested in doing something like this for Print2PDF Template, rather than the number formatting.

      string\upperCase(STRING)
      string\upperCase(name)

      I'm aware I can use Uppercase on Formula (one of my read only formula has used that), but I don't want another Field for the purpose of formula and was hoping it possible to use upperCase directly through Print2PDF.

      Planned to do something like this in Print2PDF
      {{firstName}} string\uppercase{{lastName}}

      Naturally I can create a new field call "uppcasecaselastname", then write a formula for that then in my Print2PDF template I use this special formula field.
      Last edited by espcrm; 07-01-2020, 09:29 AM.

      Comment


      • #5
        Hello espocrm, Maximus give you the right way .. you can create a custom helper and use it in pdf template like so :


        {{upperCase myLowerCaseField}}

        The helper will just return : return new LightnCandy\SafeString( strtoupper ( item) );
        see the second link of Maximus

        or you can direclty create a formula for that field in entityManager
        Last edited by item; 07-01-2020, 10:21 AM.

        Comment


        • #6
          That a new discovery then. Thanks item

          Would this code be sufficient to make this work?

          Code:
          <?php
          
          namespace Espo\Custom\TemplateHelpers;
          
          class MyHelper
          {
          public static function myHelper()
          {
          $args = func_get_args();
          $context = $args[count($args) - 1];
          $hash = $context['hash'];
          $data = $context['data']['root'];
          
          $value = $args[0] ?? null; // argument
          
          $upper = $hash['upper'] ?? '#EA1'; // option upper='VALUE'
          
          $entityType = $data['__entityType'];
          
          $html = "<span style=\"upper: {$upper};\">" . $value . "</span>";
          
          return new LightnCandy\SafeString( strtoupper ( item) );
          }
          }

          Comment


          • #7
            Hello espocrm,

            here my test sample :

            and to use so in template : {{ToUpper myField}}

            and file is : ToUpper.php

            and content is so :
            PHP Code:
            <?php

            namespace Espo\Custom\TemplateHelpers;

            class 
            ToUpper
            {
            public static function 
            ToUpper()
            {
            $args func_get_args();
            // $context = $args[count($args) - 1];  // maybe not util this

            $value $args[0] ?? null// argument

            return new LightnCandy\SafeStringstrtoupper $value ) );
            }
            }
            Maybe it's more just so to do so : strtoupper ( strtolower ( $value ) )

            Not tried but would work .. and not forget the other file json .. see link of maximus


            Last edited by item; 07-02-2020, 09:14 PM.

            Comment


            • espcrm
              espcrm commented
              Editing a comment
              Thank you. Giving it a try soon and will report back.
          Working...
          X