Announcement

Collapse
No announcement yet.

Accessing the display value of an ENUM field

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

  • Accessing the display value of an ENUM field

    Hi, is it possible to access the display value of an ENUM field in script?

  • #2
    Hi Mat,

    No.

    Comment


    • #3
      That bluntness! I laughed.

      What a you trying to do? Perhaps we can think of a "work-around" method.

      Comment


      • MatLudlam
        MatLudlam commented
        Editing a comment
        Whilst blunt, it was 100% accurate and to the point without any waffle. :-)

    • #4
      Originally posted by MatLudlam View Post
      Hi, is it possible to access the display value of an ENUM field in script?
      The question may was not clear enough, if you are talking about the javascript view class then the answer is YES you can, but may Yuri thought that you were talking about the definistion in the database.

      To access the display value of enum fied directly you edit this line :

      https://github.com/espocrm/espocrm/b...ds/enum.js#L52

      here you can play with the value as you want,

      Please note that this is not safe upgrade and to make it safe upgrade you need to define custom view class for the enum
      Last edited by eymen-elkum; 06-06-2020, 05:02 AM.
      CEO & Founder of Eblasoft.
      Professional EspoCRM development & extensions.

      Comment


      • #5
        Hi espcrm and eymen-elkum Thanks all for the feedback. Let me give a little background. We use the cloud version of ESPO so don't have access to the code behind the scenes, all we have is the script language, so this is where we have to do all of the work.

        The problem that I am trying to solve is around tracking how far an opportunity goes before it gets "Closed Lost". I want to analyse how quickly we are qualifying out of opportunities. So what I need a filed on the opportunity called maxStage that holds the furthest through the sales cycle that an Opportunity got.

        The issue is that stages are things like "Prospecting", "Demo", "Eval", "Won" etc. I can tell you the sequence but this is a real mess too write in script language.

        The correct solution would be for the programmer to have access to the sequence of ENUM value as defined in entity manager.

        The second best solution for me was to use the display names because I have them as things like "1 - Prospecting", "3 - Demo", "9 - Won". These sort nicely so I can just compare one to the other and pick the greatest.

        The 3rd best solution, that I am thinking through is around probabilities. We don't use the system maintained probability, and these do sort nicely. So I may end up with 2 fields maxStage and maxProbability and I will do all of the comparing on the latter.

        If you have any other ideas, it would be appreciated.

        In an ideal world there would be 2 new functions:
        • entity\attributeEnumDisplayName(ATTRIBUTE) - that would return the external name of an ENUM field
        • entity\attributeEnumOrder(ATTRIBUTE) - that would return the order from entity manager of the given value

        Comment


        • eymen-elkum
          eymen-elkum commented
          Editing a comment
          thanks for your detailed feedback

        • espcrm
          espcrm commented
          Editing a comment
          Sound like it is out of my league at this stage, firstly I don't even use these function (and secondly due to lack to skill and complexity in knowledge).

          In my opinion, yes, two different fields is best to be use. One for the name and one for the order (too bad we can't multi-sort yet, e.g. Sort by Number then by Name, then by something else). Don't use it as a single field, if you want it as single field better to use a "concatenate"/combine field.

          In term of tracking I see a couple of Formula on the forum where people use "days" calculation to assign these status.
      Working...
      X