Announcement

Collapse
No announcement yet.

Custom entity(event) - color in calendar based on the status

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

  • Custom entity(event) - color in calendar based on the status

    Hello guys,

    I have created a new entity event with 3 default statuses and each is being displayed in the calendar with a bit different color which is perfect. However, I have added one more custom status "Finished" and it is being displayed with exactly same color as "Held". Is there any way how to change the color for that custom status?

    Thanks a lot.

  • #2
    Hello,
    Administration -> entity manager -> your entity -> formula

    add code:
    ifThen(
    status == 'your custom status',
    color = '#822f95'
    );​
    Last edited by LuckyLouie; 05-30-2023, 01:05 PM.

    Comment


    • Jakub Grufik
      Jakub Grufik commented
      Editing a comment
      this is cool, thanks a lot!

  • #3
    do this to sort it out:

    1. Create a new varchar field for your new entity event with the name 'color'.
    2. Write formula that sets a HEX value to the 'color' attribute, depending on the 'status'.

    PHP Code:
    ifThen(entity\isAttributeChanged('status'),
    ifThen(status == "Planned"entity\setAttribute('color''#0ea5e9'));
    ifThen(status == "Held"entity\setAttribute('color''#10b981'));
    ifThen(status == "Not Held"entity\setAttribute('color''#eab308'));
    ifThen(status == "Finished"entity\setAttribute('color''#14b8a6'));
    )
    ​ 


    This will even change the colors of the event entity on the calendar to avoid mixing them with the other event entities like call - task - meeting.

    I use this trick in almost all other custom events entities i add to the system and it makes the calendar clear.

    UPDATE: FORMULA DOES NOT SUPPRT (===) IT SHOULD BE (==)
    Last edited by rabii; 06-14-2023, 03:42 PM.
    Rabii
    Web Dev

    Comment


    • Jakub Grufik
      Jakub Grufik commented
      Editing a comment
      wow I did not know this is possible. So if I understand correctly the attribute color does not exist, but if I create an attribute with name "color" it controls the color of the entity? Iam asking because as LuckyLouie mentioned above I can change color directly without creating new attribute "color". Anyway, thanks a lot for this guys. This is new for me and it is going to be super usefull

    • rabii
      rabii commented
      Editing a comment
      Yes in fact if you add a color field to any event entity and assign a color based on status it will be reflected on the calendar. so you could apply this to any event entity to display colors of statuses of different event entities to avoid confusion.

    • esforim
      esforim commented
      Editing a comment
      Is it just me? I copy paste the code and getting syntax error. I can't seem to find where it is.

      I tried removing the last ; adding extra ) but all fail.

  • #4
    rabii LuckyLouie thank you guys for the tip! Please is there any place where I can check what other attributes the entity has like the color? Because when I check api json for the entity the attribute color is not there so without your help I would not be able to figure it out.Click image for larger version

Name:	image.png
Views:	398
Size:	64.4 KB
ID:	93104

    Comment


    • Jakub Grufik
      Jakub Grufik commented
      Editing a comment
      for example if the status is "Not Held" the entity is being crossed out in the calendar. So I am wondering if I am able to control this behavior as well and if there is any attribute saying that it is crossed

    • rabii
      rabii commented
      Editing a comment
      Remember that color attribute is a bridge between the entity's status colors and the calendar display color. see this https://github.com/espocrm/espocrm/b...lendar.json#L3

  • #5
    This trick only work for Calendar right?

    We can't do this for enum Label field of other entity?
    Last edited by esforim; 06-01-2023, 12:21 AM.

    Comment


    • rabii
      rabii commented
      Editing a comment
      you are right it only works on calendar.

  • #6
    rabii LuckyLouie hello guys, I just wanted to let you know that your solution is working perfectly fine as expected! thanks a lot for the help

    Comment


    • #7
      Originally posted by rabii View Post
      do this to sort it out:

      1. Create a new varchar field for your new entity event with the name 'color'.
      2. Write formula that sets a HEX value to the 'color' attribute, depending on the 'status'.

      PHP Code:
      ifThen(entity\isAttributeChanged('status'),
      ifThen(status === "Planned"entity\setAttribute('color''#0ea5e9'));
      ifThen(status === "Held"entity\setAttribute('color''#10b981'));
      ifThen(status === "Not Held"entity\setAttribute('color''#eab308'));
      ifThen(status === "Finished"entity\setAttribute('color''#14b8a6'));
      )
      ​ 
      OK, after 30 minutes of trying and trying I got it to work with this code:

      Code:
      /// CODE GUI 1001 - Change color of Calendar for Task.
      ifThen(entity\isAttributeChanged('status'),
      ifThen(status == 'Not Started', entity\setAttribute('color', '#0ea5e9'));
      ifThen(status == 'Started', entity\setAttribute('color', '#10b981'));
      ifThen(status == 'Completed', entity\setAttribute('color', '#eab308'));
      ifThen(status == 'Canceled', entity\setAttribute('color', '#14b8a6'));
      ifThen(status == 'Deferred', entity\setAttribute('color', '#14b8a6'));
      )
      ////////////////// CODE END​
      I change the === to ==, and change the " " to ' '. Don't know if I'm doing it wrong but if I follow your code I get syntax error.

      Anyway, Thank you!

      Need to make decision on color later.

      Comment


      • #8
        espocrm when I copy paste it from here it adds dot at the end of the script and its returning syntax error, after removing the dot syntax is fine for me Click image for larger version

Name:	image.png
Views:	342
Size:	30.6 KB
ID:	93801
        Click image for larger version

Name:	image.png
Views:	346
Size:	33.2 KB
ID:	93802​​

        Comment

        Working...
        X