Announcement

Collapse
No announcement yet.

How to show the latest Product Code automatically to help creating next one

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

  • How to show the latest Product Code automatically to help creating next one

    I have 2 different kinds of products. When I start an opportunity, if it is related to a Project, it had a code like FTR_PRO_XXX (XXX = number, added manually each time I create a new opportunity).
    The problem is that, everytime I create a new opportunity, I have to check the last FTR_PRO_??? created, and define the next number.

    It could be automatically if I had only FTR_PRO_??? kind, but, sometimes, I have other types of code, like FTR_SW_XXX

    How to show the last number from the list on the side of the field when editing, helping me showing with the latest number used?

    I saw formulas like TRIM and SUBSTRING, but didn't find an way to implement it to have the desired effect. Any idea?
    Thanks

    yuri

  • #2
    Hello
    What about field type number? https://youtu.be/WDSTMNFZPLE?t=2m7s

    Comment


    • #3
      Yes, I tried it, but:

      How to increase the number only if the project type is X???

      By the way, good videos, keep posting them, please.

      Originally posted by tanya View Post
      Hello
      What about field type number? https://youtu.be/WDSTMNFZPLE?t=2m7s

      Comment


      • #4
        Originally posted by rodrigocoelho View Post
        Yes, I tried it, but:

        How to increase the number only if the project type is X???

        By the way, good videos, keep posting them, please.


        Other question Tanya,

        When I use this field type, it appears as empty and only shows the number when saving the entity. It is possible to already fill it with a value, allowing us to change it if necessary? Like a prefilled field that could be changed before saving.

        Comment


        • #5
          The easiest way is to write a hook like Number. In the hook you can set any logic


          /application/Espo/Hooks/Common/NextNumber.php

          If you want to prefill the field, you need to do this on frontend side with ajax request, to know the last number

          Comment


          • #6
            Originally posted by tanya View Post
            The easiest way is to write a hook like Number. In the hook you can set any logic

            https://www.espocrm.com/documentatio...lopment/hooks/
            /application/Espo/Hooks/Common/NextNumber.php

            If you want to prefill the field, you need to do this on frontend side with ajax request, to know the last number
            Do you think it is possible to increment workflows features to make it easier to implement for the final user? I'm user of the Advanced Pack!
            Thanks

            Comment


            • tanya
              tanya commented
              Editing a comment
              It won't be easier, because in any case you need to get the last used number from database. With workflow for this you can use only "Run Workflow Service" Action. But you need to develop this method in any case, and workflow will be triggered after! record saved. With hook you can set this field before record saved.

          • #7
            Originally posted by tanya View Post
            The easiest way is to write a hook like Number. In the hook you can set any logic


            /application/Espo/Hooks/Common/NextNumber.php

            If you want to prefill the field, you need to do this on frontend side with ajax request, to know the last number
            Tanya, do you have example of this frontend side code, doing an ajax request to get that number ?

            It could be very helpfull

            Thx

            Comment


            • #8
              Originally posted by rodrigocoelho View Post

              Do you think it is possible to increment workflows features to make it easier to implement for the final user? I'm user of the Advanced Pack!
              Thanks
              Any chance to create a function that would decrease the NextNumber value? For example NextNumber = NextNumber - 1;

              If so, I could check if the opportunity type is different from that I was expecting for the NextNumber, and, than, would ask to rollback the increased number.

              May you ask this for yuri ??

              Thanks tanya

              Comment


              • #9
                Create beforeSave hook with order 11+
                there you can unset the value of your number field. And decrease NextNumber reverting the logic from application/Espo/Hooks/Common/NextNumber.php

                Comment


                • #10
                  Originally posted by tanya View Post
                  Create beforeSave hook with order 11+
                  there you can unset the value of your number field. And decrease NextNumber reverting the logic from application/Espo/Hooks/Common/NextNumber.php
                  Ops, I'm not a programmer. Just a EspoCRM user. So, I need to use the great functions and resources created by you on EspoCRM base or Advanced Pack.

                  That's why I migrated to EspoCRM, because you delivered special tools for non programmers.

                  I have no idea of how to implement hooks or programming in PHP.

                  Will need to wait a new feature from yuri to help me accomplish this!

                  Thanks Tanya.

                  Comment

                  Working...
                  X