Announcement

Collapse
No announcement yet.

Count number of cases on contact

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

  • rabii
    commented on 's reply
    you should create a new field on the contact entity using the entity manager and you can call it caseCount or whatever name you like.

  • VladZP
    replied
    PHP Code:
    record\update('Contact'contactId'countCase'$caseCount 1); 
    All clear, but where do you have 'countCase'? New field name called caseCount. In documentation I saw Attribute1, Value1 and tried something like Contact.caseCount, 'caseCount', caseCount, but it doesn't work

    Leave a comment:


  • hrdy90
    commented on 's reply
    Fantastic. Worked like a charm! I forgot to set "Default" or "Minimum value" for the integer field though but that will solve itself over time. Now the first incoming case for already created contact will change from "Null" to 0 and go up from there. But no biggie :'D

    Thank you!

  • rabii
    replied
    Yeah possible.
    You can create a field (int) in the contact entity and you can simply use formula script to count related case on the contact entity, e.g:
    PHP Code:
    // Assuming that the new field which hold the count is called caseCount
    caseCount entity\countRelated('cases'); 
    Remember that this is a before save script which mean if a new case is created and been related to a contact then you should have a reversed script on the case to update the caseCount on the contact entity, somthing like below, formula on the Case entity:
    PHP Code:
    ifThen(entity\isNew() && contactId,
    $caseCount record\attribute('Contact'contactId'caseCount');
    record\update('Contact'contactId'countCase'$caseCount 1);
    );
    ‚Äč 

    Leave a comment:


  • hrdy90
    started a topic Count number of cases on contact

    Count number of cases on contact

    I'm creating a contact when a case is created (email-to-case). When looking at the contact-card I can see a list of which Cases that user has sent in.

    I would like to have an entity that shows a count on how many cases there is and display it in the Contact list layout. Is this possible?
Working...
X