Formatting a Float custom field to Percent %

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Triggerz
    Senior Member
    • May 2024
    • 161

    #1

    Formatting a Float custom field to Percent %

    Hi,

    I am looking on a way to format a float custom field so that it will reflect as % similar to the Tax Rate field in Quoteitems entity.

    Thanks in advance and warm regards...
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1857

    #2
    You can use a formula for that.
    You will need one field for the input of your percebtage value and another float for the decimal result.

    PHP Code:
    percentage_value_dec percentage_value/100

    Comment

    • Triggerz
      Senior Member
      • May 2024
      • 161

      #3
      Thanks shalmaxb. Not sure though where I should put the code. Is there an available documentation guide on how to apply this? Thanks

      Comment

      • shalmaxb
        Senior Member
        • Mar 2015
        • 1857

        #4
        you go to your entity in the admin panel (entity manager). There you will see some options, one is formula. Click taht option and in the following dialogue you select custom before save script. A type of code editor opens and you can set your formula there,
        Information in the documantation: https://docs.espocrm.com/administration/formula/

        As you not seem familiar with that, you might have to study a bit about it first.

        Comment

        • Triggerz
          Senior Member
          • May 2024
          • 161

          #5
          Hi shalmaxb, the Markup field is in the Quoteitem entity. How can I do this in the Formula if there are multiple Quoteitem?

          Comment

          • victor
            Active Community Member
            • Aug 2022
            • 1147

            #6
            Triggerz ,

            1. Create the required field in Administration > Entity Manager > Quote Item > Fields (screenshot 1).
            2. Add this field in Administration > Entity Manager > Quote Item > Layouts > List (Item) (screenshot 2).
            3. Add the simple formula that we wrote about above in Administration > Entity Manager > Quote Item > Formula > Before Save Custom Script (screenshot 3).
            Code:
            cFloatCustomField = cFloatCustomField/100;
            In the end, you will get the calculation in the custom field that you requested. However, you will not be able to make it similar to Taxe Rate (for example, have a "%" sign directly in this field). You will have a regular number (screenshot 4). You can specify the percent sign in the Label of this field in step 1.

            - What exactly are you trying to achieve by creating this field in QuoteItem?
            - Should this field affect certain calculations only in the QuoteItem or in the entire Quote to which this QuoteItem belongs?
            Attached Files

            Comment

            • Triggerz
              Senior Member
              • May 2024
              • 161

              #7
              Hi Victor,

              The goal is to affect the entire Quote calculation where the Quoteitem belongs to.

              Regards...

              Comment

            • Triggerz
              Senior Member
              • May 2024
              • 161

              #8
              Thanks Victor. I have already implemented the calculation. I just wanted the Markup to be displayed as % in the list of Quoteitems. Similar to how the Tax Rate is being displayed.

              I tried formatting it using ClientDefs and adding the code below but it does not work.

              Code:
              {
              "fields": {
              "cmarkup": {
              "style": "percent"
              }
              }
              }

              Comment

              Working...