Announcement

Collapse
No announcement yet.

Get only year from Datefield

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

  • Get only year from Datefield

    This has been asked here and also solved, but it does not work for me.
    I have one field "year" with datetime\now()
    I have another field "invoice-year", that I want to show only the year, not month or day.
    These are the two formulas, use, but it does not work, the "invoice-year" still shows the complete datetime field:

    Code:
    year=datetime\now();
    invoice-year=datetime\format(year, 'YYYY');
    Any help, what is going wrong here?

  • #2
    Try to go to entityDefs/YourScope.json and edit the definition of the year field as following:

    Code:
           "invoiceYear": {
                  "select":"YEAR(date_field_name_here)"
           }
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment


    • #3
      Thank you, but unfortunately this did not work. I now get an error 500. To complete my question:

      espoCRM 6.0.3
      year -> datetime field
      invoiceYear->datetimefield

      @eymen-elkum: in your solution the formula, I used is obsolete or will I have to use it anyway?

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        If the solution worked then no need for the formula,

      • shalmaxb
        shalmaxb commented
        Editing a comment
        did not work, error 500 and empty detail view

    • #4
      With the help of eymen-elkum this problem has been sorted out. Whoever has to solve this, here the important direction (I refer to the mentioned fields in my first post):

      To use the function datetime\format, as well as datetime\year, you will need two fields. One field (in my case year), has to be a datetime field. This field does not necessarily have to be created, if you have another field, that is already present in the entity (in my case, I had a field invoiceDate, a datefield with one date, from where I could extract the year), you can use that field as the value.
      Then you need another field, where you will show the extracted year. This HAS TO BE a varchar field. This is due to the fact, that datetime in mysql is a string, from where we extract a part.
      If you then use the formula as written in the documentation, the year part of the first field will be extracted in the second field. Unfortunately the documentation lacks this information.

      Further information: The possibility to edit directly the json file in the entityDef does not work anymore in espoCRM 6.0.3.

      Comment


      • eymen-elkum
        eymen-elkum commented
        Editing a comment
        Thanks for the report, because the lack of time I couldn't report it
    Working...
    X