Cannot format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nocstaff@urbancom.net
    Member
    • Jul 2025
    • 61

    #1

    Cannot format

    I made a custom entity called total job time, and I tried to make an entity based report template that includes this. However, it calculates in the report as seconds. I tried to adding formation coding in the html like

    HTML Code:
    <strong>Total Job Time:</strong> {{duration\format(duration)}}
    and I also tried to calculate it within the html and produce that output like here

    HTML Code:
    <tr>
    <td style="width:50%;">
    <strong>Completion Time:</strong> {{dateEnd}}
    </td>
    <td style="width:50%;">
    <strong>Total Job Time:</strong> {{duration\format(duration)}}
    </td>
    </tr>
    but nothing I tried worked, it always ended up with either a blank response or an error 500. I also tried to add a formula script before save custom script, but that usually just ended in an error too. How can I fix this?
    Attached Files
  • victor
    Active Community Member
    • Aug 2022
    • 1008

    #2
    Report Template is not a regular PDF Template - it is more complex and the possible customizations here are very minimal.

    You edited the Report Template and inserted {{duration\format(duration)}}. Who advised you to do this?

    What does your Report look like?

    Comment

    • nocstaff@urbancom.net
      Member
      • Jul 2025
      • 61

      #3
      I just looked up how to change duration formatting and it was one of the first results from google's AI Overview. I'm still pretty unfamiliar with what is and isn't allowed when trying to format reports with html coding, since it doesn't seem to be purely html, and it seems like a lot of terms just gets ignored, so it's been a matter of trial and error for me. I know there's 2 ways of making a report to a pdf, I am doing it through this method: https://www.espocrm.com/tips/pdf-template/

      If it helps you, this is what the full html code is for the template, and attached is a screenshot of what it generates

      HTML Code:
      <h1>Daily Log {{date}}</h1>
      
      <table cellpadding="5" cellspacing="0" width="100%" nobr="true" style="margin: 0;">
        <tbody>
          <tr>
            <td style="width:25%;">
              <strong>Log Type:</strong> {{type}}
            </td>
            <td style="width:25%;">
              <strong>Status:</strong> {{status}}
            </td>
            <td style="width:25%;">
              <strong>Account:</strong> {{parentName}}
            </td>
            <td style="width:25%;">
              <strong>Case:</strong> {{casesNames}}
            </td>
          </tr>
          <tr>
            <td style="width:50%;">
              <strong>Dispatch Time:</strong> {{dateStart}}
            </td>
            <td style="width:50%;">
              <strong>Arrival Time:</strong> {{arrivalTime}}
            </td>
          </tr>
          <tr>
            <td style="width:50%;">
              <strong>Completion Time:</strong> {{dateEnd}}
            </td>
            <td style="width:50%;">
              <strong>Total Job Time:</strong> {{duration}}s
            </td>
          </tr>
          <tr>
            <td style="width:100%;">
              <strong>Description: </strong> {{{description}}}
            </td>
          </tr>
          <tr>
            <td colspan="4" style="height: 20px; border: none;"></td>
          </tr>
        </tbody>
      </table>
      Attached Files

      Comment

      • lazovic
        Super Moderator
        • Jan 2022
        • 1155

        #4
        Hi nocstaff@urbancom.net,

        Create a varchar field named durationText and insert the following formula script into the formula for your event entity:
        Code:
        $seconds = duration;
        
        $days = number\floor($seconds / 86400);
        $hours = number\floor(($seconds % 86400) / 3600);
        $minutes = number\floor(($seconds % 3600) / 60);
        
        durationText = '';
        
        if ($days > 0) {
            durationText = string\concatenate(durationText, $days, 'd');
        }
        
        if ($hours > 0) {
            if (durationText != '') {
                durationText = string\concatenate(durationText, ' ', $hours, 'h');
            } else {
                durationText = string\concatenate(durationText, $hours, 'h');
            }
        }
        
        if ($minutes > 0) {
            if (durationText != '') {
                durationText = string\concatenate(durationText, ' ', $minutes, 'm');
            } else {
                durationText = string\concatenate(durationText, $minutes, 'm');
            }
        }
        
        if (durationText == '') {
            durationText = '0m';
        }
        Recalculate the formula on the event entity list view for all existing records and use the durationText​ field in your PDF template instead of the duration field.
        ​

        Comment

        • nocstaff@urbancom.net
          Member
          • Jul 2025
          • 61

          #5
          I tried this fix, but it always gives me "5m" as a result now. Is there something I did wrong along the way? For the formula you gave me, I placed it in the "Before Save Custom Script" option
          Attached Files

          Comment

          • lazovic
            Super Moderator
            • Jan 2022
            • 1155

            #6
            nocstaff@urbancom.net,

            Can you please show the Names of your fields from Administration > Entity Manager > Daily Log > Fields?

            Comment

            • nocstaff@urbancom.net
              Member
              • Jul 2025
              • 61

              #7
              here's a list of every field in that entity
              Attached Files

              Comment


              • lazovic
                lazovic commented
                Editing a comment
                The formula script looks correct. It also works correctly for me. It is not yet clear what the problem could be. Try to display the Duration Text field on the layout and recalculate the formula again.
            • nocstaff@urbancom.net
              Member
              • Jul 2025
              • 61

              #8
              I've been doing a bit of testing and discovered something. I tried editing the dispatch time and completion time to change the total job time's value from 1hr 30min to 2hrs, and when I try to generate a pdf again, now it shows as 1hr 30min. when I try to do that again and change it to something else, the new value is 2hrs. I made a new daily log and set it to 30 minutes, but the report first shows 5 minutes, and is always what the previous value was after I make changes. Do you know why this may be happening? I first put the formula in the "Before Save Custom Script" section, but I also tried the "API Before Save Script" option and still nothing changed

              Comment

              • lazovic
                Super Moderator
                • Jan 2022
                • 1155

                #9
                nocstaff@urbancom.net,

                Try to replace the first line in the formula script with this one:
                Code:
                $seconds = datetime\diff(dateEnd, dateStart, 'seconds');

                Comment

                • nocstaff@urbancom.net
                  Member
                  • Jul 2025
                  • 61

                  #10
                  Now it's working perfectly. Thank you so much

                  Comment

                  Working...