Printing to PDF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpennington
    Member
    • Jun 2018
    • 52

    Printing to PDF

    Is it possible to only print a filed to PDF, if it is not empty?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Yes.

    Code:
    {{#if fieldName}} {{fieldName}} ​​​​​​​{{/if}}
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • jpennington
      Member
      • Jun 2018
      • 52

      #3
      Thank you! Now I understand what I was doing wrong

      Comment

      • hermann
        Junior Member
        • Apr 2020
        • 2

        #4
        Is it also possible to check whether a field contains a certain character or word? I'm stuck with the depending on the output in PDF!

        EXAMPLE
        Code:
        {{#if fieldName == "example" }} "set this text" {{/if}}

        Comment

        • yuri
          Member
          • Mar 2014
          • 8440

          #5
          You can create a custom field of boolean type (set it read-only), and use formula (before-update script) to set true or false depending on whether your field contains word.

          Formula:
          Code:
          myCustomBoolField = string\contains(fieldName, 'needle');
          Then when you print PDF you can check this boolean field.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • esforim
            Active Community Member
            • Jan 2020
            • 2204

            #6
            Does this also work for formula? For example I don't want a "comma" to show up this if the field addressStreet is empty.

            Original formula
            folderName=string\concatenate(addressStreet, ", ", addressCity");

            How would this become formula?

            None of the Operators seem to match for blank https://docs.espocrm.com/administrat...ula/#operators

            Comment

            • yuri
              Member
              • Mar 2014
              • 8440

              #7
              You need to use ifThen.

              Code:
              folderName = null;
              ifThen(  
                addressStreet,
                folderName = string\concatenate(addressStreet, ", ", addressCity)
              );
              If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

              Comment


              • esforim
                esforim commented
                Editing a comment
                folderName = null;

                I believe this code is to clear out any existing data in folderName, but is there any "programmer" secret behind the reason to doing that? Formula work without it.

              • yuri
                yuri commented
                Editing a comment
                If your addressStreet will change its value to empty, then folderName will be erased too.
            • esforim
              Active Community Member
              • Jan 2020
              • 2204

              #8
              Print2PDF PDF_ ifThenElse code

              Thank you yurikuzn.

              Please ignore following paragraph if you just want the code. These are just my insight and input in learning.

              It took a while to get it to work the way I wanted, the above code will leave your folder name blank (null/none) if street is missing. This isn't what I truly wanted. After thinking about it a little I finally understood something. The way it is formatted make it look easier to the eyes so I didn't understand that at first. Then I remembered that were was another "if" code and after trying that I got it to work as I wanted it to. Of course it does have it weakness at the moment but I suppose the secret to "if blank" is not to give it any condition(?), hence it just a ", comma" straight after addressStreet.

              I suppose next issue is, should I breakdown the paragraph further or leave it long row. Secondly is, what if the State or Postcode were missing, is there a better way to chain "if" code or a secondary if code should use instead.

              Anyway here is my final code with the full data and simplified data for a "folder/file name"

              Code:
              ifThenElse(
              addressStreet,
              folderName = string\concatenate(addressStreet, ", ", addressCity, " ", addressState, " ", addressPostalCode," (", propertyID, ")"),
              folderName = string\concatenate(addressCity, " ", addressState, " ", addressPostalCode," (", propertyID, ")")
              );
              (Used: https://www.randomlists.com/random-addresses to generator fake test data).

              847 Liberty Ave
              Dorchester Center MA 02124


              Result is as follow if there was an Street address:

              847 Liberty Ave, Dorchester Center MA 02124 (ID123)

              Result is as follow if there was no treet address:
              Dorchester Center MA 02124 (ID123)

              Result if you don't have this formula and just use a string\concatenate for an address without Street name. Look very funny.
              , Dorchester Center MA 02124 (ID123)
              Last edited by esforim; 07-15-2020, 12:44 AM.

              Comment

              Working...